opentelemetry-instrumentation-active_model_serializers 0.20.2 → 0.20.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4036ec3461c627794cc6678d700ad42e497a41cb163f632436d9575f660e45c8
4
- data.tar.gz: 63c4b031ec8f79f3f5334d3f36d5161d89cdf9b8d59b71a78a660829c2eea8ee
3
+ metadata.gz: 79b4ebdf892853ac5b800c445abba347e9a985e1cba611493aff3ef4bc322092
4
+ data.tar.gz: 62430d20906a9614ddae4fea5015e6e2e171268c048e852c33a531c609bb1635
5
5
  SHA512:
6
- metadata.gz: 44753ed11da02847235978f49e82978661563c0dfd5aeac74ba1fb81cc12e1ad5be8c6e98cc161132bc357df55d65808cb1119d63ad5728e423787b36685ec10
7
- data.tar.gz: 9079296d8ec418e531febdd94443f1cd85e3cae71cbe7dbc61e7246fcf2679463a27e7659f2d35b6f44171c44995b7303240373a63098bd7cdd20a91c6b8f224
6
+ metadata.gz: 9626d66b283b78643c2bde5b7a975f1802ad726a4a178386bf2743762f3fe30fb98ef779c36dc2dbd592abe4b9a19c0a118d26fbbe1a31775a92abdc7f638286
7
+ data.tar.gz: 390d8337a2f50566fcea3a9ff61561a504b26f8acac8ee6f9c31f07ac0ce58fc5be84027efe75dcd885a022d1b193cda28355a0d900a8c06a4bbba6cc06c40de
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Release History: opentelemetry-instrumentation-active_model_serializers
2
2
 
3
+ ### v0.20.3 / 2024-12-04
4
+
5
+ * FIXED: Use ActiveSupport::Notifications subscriber to serialize events.
6
+
3
7
  ### v0.20.2 / 2024-07-23
4
8
 
5
9
  * DOCS: Add cspell to CI
data/README.md CHANGED
@@ -6,7 +6,7 @@ The OpenTelemetry Active Model Serializers gem is a community maintained instrum
6
6
 
7
7
  Install the gem using:
8
8
 
9
- ```
9
+ ```console
10
10
  gem install opentelemetry-instrumentation-active_model_serializers
11
11
  ```
12
12
 
@@ -38,7 +38,7 @@ Example usage of active_model_serializers can be seen in the `./example/active_m
38
38
 
39
39
  The `opentelemetry-instrumentation-active_model_serializers` gem source is [on github][repo-github], along with related gems including `opentelemetry-api` and `opentelemetry-sdk`.
40
40
 
41
- The OpenTelemetry Ruby gems are maintained by the OpenTelemetry-Ruby special interest group (SIG). You can get involved by joining us in [GitHub Discussions][discussions-url] or attending our weekly meeting. See the [meeting calendar][community-meetings] for dates and times. For more information on this and other language SIGs, see the OpenTelemetry [community page][ruby-sig].
41
+ The OpenTelemetry Ruby gems are maintained by the OpenTelemetry Ruby special interest group (SIG). You can get involved by joining us on our [GitHub Discussions][discussions-url], [Slack Channel][slack-channel] or attending our weekly meeting. See the [meeting calendar][community-meetings] for dates and times. For more information on this and other language SIGs, see the OpenTelemetry [community page][ruby-sig].
42
42
 
43
43
  ## License
44
44
 
@@ -50,4 +50,5 @@ Apache 2.0 license. See [LICENSE][license-github] for more information.
50
50
  [license-github]: https://github.com/open-telemetry/opentelemetry-ruby-contrib/blob/main/LICENSE
51
51
  [ruby-sig]: https://github.com/open-telemetry/community#ruby-sig
52
52
  [community-meetings]: https://github.com/open-telemetry/community#community-meetings
53
+ [slack-channel]: https://cloud-native.slack.com/archives/C01NWKKMKMY
53
54
  [discussions-url]: https://github.com/open-telemetry/opentelemetry-ruby/discussions
@@ -4,16 +4,24 @@
4
4
  #
5
5
  # SPDX-License-Identifier: Apache-2.0
6
6
 
7
+ require 'opentelemetry-instrumentation-active_support'
8
+
7
9
  module OpenTelemetry
8
10
  module Instrumentation
9
11
  module ActiveModelSerializers
10
12
  # Instrumentation class that detects and installs the ActiveModelSerializers instrumentation
11
13
  class Instrumentation < OpenTelemetry::Instrumentation::Base
14
+ # Minimum supported version of the `active_model_serializers` gem
12
15
  MINIMUM_VERSION = Gem::Version.new('0.10.0')
13
16
 
17
+ # ActiveSupport::Notification topics to which the instrumentation subscribes
18
+ SUBSCRIPTIONS = %w[
19
+ render.active_model_serializers
20
+ ].freeze
21
+
14
22
  install do |_config|
23
+ install_active_support_instrumenation
15
24
  require_dependencies
16
- register_event_handler
17
25
  end
18
26
 
19
27
  present do
@@ -24,24 +32,39 @@ module OpenTelemetry
24
32
  !defined?(::ActiveSupport::Notifications).nil? && gem_version >= MINIMUM_VERSION
25
33
  end
26
34
 
35
+ def subscribe
36
+ SUBSCRIPTIONS.each do |subscription_name|
37
+ OpenTelemetry.logger.debug("Subscribing to #{subscription_name} notifications with #{_tracer}")
38
+ OpenTelemetry::Instrumentation::ActiveSupport.subscribe(_tracer, subscription_name, default_attribute_transformer)
39
+ end
40
+ end
41
+
27
42
  private
28
43
 
44
+ def _tracer
45
+ self.class.instance.tracer
46
+ end
47
+
29
48
  def gem_version
30
49
  Gem::Version.new(::ActiveModel::Serializer::VERSION)
31
50
  end
32
51
 
33
- def require_dependencies
34
- require_relative 'event_handler'
52
+ def install_active_support_instrumenation
53
+ OpenTelemetry::Instrumentation::ActiveSupport::Instrumentation.instance.install({})
35
54
  end
36
55
 
37
- def register_event_handler
38
- ::ActiveSupport::Notifications.subscribe(event_name) do |_name, start, finish, _id, payload|
39
- EventHandler.handle(start, finish, payload)
40
- end
56
+ def require_dependencies
57
+ require_relative 'railtie'
41
58
  end
42
59
 
43
- def event_name
44
- 'render.active_model_serializers'
60
+ def default_attribute_transformer
61
+ lambda { |payload|
62
+ {
63
+ 'serializer.name' => payload[:serializer].name,
64
+ 'serializer.renderer' => 'active_model_serializers',
65
+ 'serializer.format' => payload[:adapter]&.class&.name || 'default'
66
+ }
67
+ }
45
68
  end
46
69
  end
47
70
  end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright The OpenTelemetry Authors
4
+ #
5
+ # SPDX-License-Identifier: Apache-2.0
6
+
7
+ module OpenTelemetry
8
+ module Instrumentation
9
+ module ActiveModelSerializers # :nodoc:
10
+ def self.subscribe
11
+ Instrumentation.instance.subscribe
12
+ end
13
+
14
+ if defined?(::Rails::Railtie)
15
+ # This Railtie sets up subscriptions to relevant ActiveModelSerializers notifications
16
+ class Railtie < ::Rails::Railtie
17
+ config.after_initialize do
18
+ ::OpenTelemetry::Instrumentation::ActiveModelSerializers.subscribe
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -7,7 +7,7 @@
7
7
  module OpenTelemetry
8
8
  module Instrumentation
9
9
  module ActiveModelSerializers
10
- VERSION = '0.20.2'
10
+ VERSION = '0.20.3'
11
11
  end
12
12
  end
13
13
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opentelemetry-instrumentation-active_model_serializers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.20.2
4
+ version: 0.20.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - OpenTelemetry Authors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-07-24 00:00:00.000000000 Z
11
+ date: 2024-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opentelemetry-api
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: opentelemetry-instrumentation-active_support
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.6.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.6.0
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: opentelemetry-instrumentation-base
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -142,28 +156,28 @@ dependencies:
142
156
  requirements:
143
157
  - - "~>"
144
158
  - !ruby/object:Gem::Version
145
- version: 1.65.0
159
+ version: 1.68.0
146
160
  type: :development
147
161
  prerelease: false
148
162
  version_requirements: !ruby/object:Gem::Requirement
149
163
  requirements:
150
164
  - - "~>"
151
165
  - !ruby/object:Gem::Version
152
- version: 1.65.0
166
+ version: 1.68.0
153
167
  - !ruby/object:Gem::Dependency
154
168
  name: rubocop-performance
155
169
  requirement: !ruby/object:Gem::Requirement
156
170
  requirements:
157
171
  - - "~>"
158
172
  - !ruby/object:Gem::Version
159
- version: '1.20'
173
+ version: 1.23.0
160
174
  type: :development
161
175
  prerelease: false
162
176
  version_requirements: !ruby/object:Gem::Requirement
163
177
  requirements:
164
178
  - - "~>"
165
179
  - !ruby/object:Gem::Version
166
- version: '1.20'
180
+ version: 1.23.0
167
181
  - !ruby/object:Gem::Dependency
168
182
  name: simplecov
169
183
  requirement: !ruby/object:Gem::Requirement
@@ -184,14 +198,14 @@ dependencies:
184
198
  requirements:
185
199
  - - "~>"
186
200
  - !ruby/object:Gem::Version
187
- version: '3.19'
201
+ version: 3.24.0
188
202
  type: :development
189
203
  prerelease: false
190
204
  version_requirements: !ruby/object:Gem::Requirement
191
205
  requirements:
192
206
  - - "~>"
193
207
  - !ruby/object:Gem::Version
194
- version: '3.19'
208
+ version: 3.24.0
195
209
  - !ruby/object:Gem::Dependency
196
210
  name: yard
197
211
  requirement: !ruby/object:Gem::Requirement
@@ -220,17 +234,17 @@ files:
220
234
  - lib/opentelemetry-instrumentation-active_model_serializers.rb
221
235
  - lib/opentelemetry/instrumentation.rb
222
236
  - lib/opentelemetry/instrumentation/active_model_serializers.rb
223
- - lib/opentelemetry/instrumentation/active_model_serializers/event_handler.rb
224
237
  - lib/opentelemetry/instrumentation/active_model_serializers/instrumentation.rb
238
+ - lib/opentelemetry/instrumentation/active_model_serializers/railtie.rb
225
239
  - lib/opentelemetry/instrumentation/active_model_serializers/version.rb
226
240
  homepage: https://github.com/open-telemetry/opentelemetry-ruby-contrib
227
241
  licenses:
228
242
  - Apache-2.0
229
243
  metadata:
230
- changelog_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-active_model_serializers/0.20.2/file/CHANGELOG.md
244
+ changelog_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-active_model_serializers/0.20.3/file/CHANGELOG.md
231
245
  source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/tree/main/instrumentation/active_model_serializers
232
246
  bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby-contrib/issues
233
- documentation_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-active_model_serializers/0.20.2
247
+ documentation_uri: https://rubydoc.info/gems/opentelemetry-instrumentation-active_model_serializers/0.20.3
234
248
  post_install_message:
235
249
  rdoc_options: []
236
250
  require_paths:
@@ -1,48 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright The OpenTelemetry Authors
4
- #
5
- # SPDX-License-Identifier: Apache-2.0
6
-
7
- module OpenTelemetry
8
- module Instrumentation
9
- module ActiveModelSerializers
10
- # Event handler singleton for ActiveModelSerializers
11
- module EventHandler
12
- extend self
13
-
14
- def handle(start_timestamp, end_timestamp, payload)
15
- tracer.start_span(span_name(payload),
16
- start_timestamp: start_timestamp,
17
- attributes: build_attributes(payload),
18
- kind: :internal)
19
- .finish(end_timestamp: end_timestamp)
20
- end
21
-
22
- protected
23
-
24
- def span_name(payload)
25
- "#{demodulize(payload[:serializer].name)} render"
26
- end
27
-
28
- def build_attributes(payload)
29
- {
30
- 'serializer.name' => payload[:serializer].name,
31
- 'serializer.renderer' => 'active_model_serializers',
32
- 'serializer.format' => payload[:adapter]&.class&.name || 'default'
33
- }
34
- end
35
-
36
- def tracer
37
- ActiveModelSerializers::Instrumentation.instance.tracer
38
- end
39
-
40
- def demodulize(string)
41
- string = string.to_s
42
- i = string.rindex('::')
43
- i ? string[(i + 2)..-1] : string
44
- end
45
- end
46
- end
47
- end
48
- end