opentelemetry-instrumentation-action_view 0.1.2 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 90c7bcecc2f3949e79523c0406503212f2bc54477aaf4dd677314e164a09067c
4
- data.tar.gz: 042d4e54e62d8650079a50066e6a9b739524f5fa47f68cf9980e41c0babdaa92
3
+ metadata.gz: 1d0354ffa37debf3799aa0f4ae55c5e88b258df843379c78cd0bfa48ed42fdd8
4
+ data.tar.gz: 63428a658d4053054980ac4912f41a0e56d451e2577d4d10e1cc9ba1bd4ec648
5
5
  SHA512:
6
- metadata.gz: 165bcf906fd27e99c35acbd3421375544a9fc7531eef8939f75713fa6b2f94b557c5d6e929981928cf1fcca71683f9c2120535ce30ff6bab0ea36569a51fd9b5
7
- data.tar.gz: f2ee6bfee8771aae53d7301ad9c0eb56df55996fde55a4b5a38b2c9d2d9cf3ea7e06be7621d6dbdbf83f4d802bbc026455b65389cc601e6e8a40310c22432911
6
+ metadata.gz: 4f5170a008ee10e0af8766dd67b6bcca388ad6529799ab04bdcd542c91bbee4b406434287354084d8f9760dcb3507e68db8f164d54abe106c570364eb3d38209
7
+ data.tar.gz: 5ff0b8c8a9f0a43419e3cd31162c4aab1ec3bccf17eb03ec017da5206b7fea0e561cd227d30fa2600cc48d7fdb27c5bd7b729e0d3e8641308cb83bf50ebd45db
data/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Release History: opentelemetry-instrumentation-action_view
2
2
 
3
+ ### v0.2.1 / 2022-05-02
4
+
5
+ * FIXED: RubyGems Fallback
6
+
7
+ ### v0.2.0 / 2021-12-01
8
+
9
+ * ADDED: Move activesupport notification subsciber out of action_view gem
10
+ * FIXED: Instrumentation of Rails 7
11
+
12
+ ### v0.1.3 / 2021-10-06
13
+
14
+ * FIXED: Do not replace fanout
15
+
3
16
  ### v0.1.2 / 2021-09-29
4
17
 
5
18
  * (No significant changes)
data/README.md CHANGED
@@ -36,6 +36,22 @@ end
36
36
 
37
37
  Example usage can be seen in the `./example/trace_request_demonstration.ru` file [here](https://github.com/open-telemetry/opentelemetry-ruby/blob/main/instrumentation/action_view/example/trace_request_demonstration.ru)
38
38
 
39
+ ## Known issues
40
+
41
+ ActionView instrumentation uses ActiveSupport notifications and in the case when a subscriber raises in start method an unclosed span would break successive spans ends. Example:
42
+
43
+ ```ruby
44
+ class CrashingEndSubscriber
45
+ def start(name, id, payload)
46
+ raise 'boom'
47
+ end
48
+
49
+ def finish(name, id, payload) end
50
+ end
51
+
52
+ ::ActiveSupport::Notifications.subscribe('render_template.action_view', CrashingStartSubscriber.new)
53
+ ```
54
+
39
55
  ## How can I get involved?
40
56
 
41
57
  The `opentelemetry-instrumentation-action_view` gem source is [on github][repo-github], along with related gems including `opentelemetry-api` and `opentelemetry-sdk`.
@@ -19,7 +19,7 @@ module OpenTelemetry
19
19
  end
20
20
 
21
21
  compatible do
22
- Gem.loaded_specs['actionview'].version >= MINIMUM_VERSION
22
+ gem_version >= MINIMUM_VERSION
23
23
  end
24
24
 
25
25
  option :disallowed_notification_payload_keys, default: [], validate: :array
@@ -27,9 +27,11 @@ module OpenTelemetry
27
27
 
28
28
  private
29
29
 
30
+ def gem_version
31
+ ::ActionView.version
32
+ end
33
+
30
34
  def require_dependencies
31
- require_relative 'fanout'
32
- require_relative 'span_subscriber'
33
35
  require_relative 'railtie'
34
36
  end
35
37
  end
@@ -15,17 +15,12 @@ module OpenTelemetry
15
15
 
16
16
  # This Railtie sets up subscriptions to relevant ActionView notifications
17
17
  class Railtie < ::Rails::Railtie
18
- config.before_initialize do
19
- ::ActiveSupport::Notifications.notifier = Fanout.new(::ActiveSupport::Notifications.notifier)
20
- end
21
-
22
18
  config.after_initialize do
19
+ ::OpenTelemetry::Instrumentation::ActiveSupport::Instrumentation.instance.install({})
20
+
23
21
  SUBSCRIPTIONS.each do |subscription_name|
24
- subscriber = OpenTelemetry::Instrumentation::ActionView::SpanSubscriber.new(
25
- name: subscription_name,
26
- tracer: ActionView::Instrumentation.instance.tracer
27
- )
28
- ::ActiveSupport::Notifications.notifier.subscribe(subscription_name, subscriber)
22
+ config = ActionView::Instrumentation.instance.config
23
+ ::OpenTelemetry::Instrumentation::ActiveSupport.subscribe(ActionView::Instrumentation.instance.tracer, subscription_name, config[:notification_payload_transform], config[:disallowed_notification_payload_keys])
29
24
  end
30
25
  end
31
26
  end
@@ -7,7 +7,7 @@
7
7
  module OpenTelemetry
8
8
  module Instrumentation
9
9
  module ActionView
10
- VERSION = '0.1.2'
10
+ VERSION = '0.2.1'
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-action_view
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - OpenTelemetry Authors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-30 00:00:00.000000000 Z
11
+ date: 2022-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opentelemetry-api
@@ -24,20 +24,34 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.0.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.1.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.1.0
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: opentelemetry-instrumentation-base
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: 0.18.0
47
+ version: 0.20.0
34
48
  type: :runtime
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
52
  - - "~>"
39
53
  - !ruby/object:Gem::Version
40
- version: 0.18.0
54
+ version: 0.20.0
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: appraisal
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -206,19 +220,17 @@ files:
206
220
  - lib/opentelemetry-instrumentation-action_view.rb
207
221
  - lib/opentelemetry/instrumentation.rb
208
222
  - lib/opentelemetry/instrumentation/action_view.rb
209
- - lib/opentelemetry/instrumentation/action_view/fanout.rb
210
223
  - lib/opentelemetry/instrumentation/action_view/instrumentation.rb
211
224
  - lib/opentelemetry/instrumentation/action_view/railtie.rb
212
- - lib/opentelemetry/instrumentation/action_view/span_subscriber.rb
213
225
  - lib/opentelemetry/instrumentation/action_view/version.rb
214
226
  homepage: https://github.com/open-telemetry/opentelemetry-ruby
215
227
  licenses:
216
228
  - Apache-2.0
217
229
  metadata:
218
- changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-instrumentation-action_view/v0.1.2/file.CHANGELOG.html
230
+ changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-instrumentation-action_view/v0.2.1/file.CHANGELOG.html
219
231
  source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby/tree/main/instrumentation/action_view
220
232
  bug_tracker_uri: https://github.com/open-telemetry/opentelemetry-ruby/issues
221
- documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-instrumentation-action_view/v0.1.2
233
+ documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-instrumentation-action_view/v0.2.1
222
234
  post_install_message:
223
235
  rdoc_options: []
224
236
  require_paths:
@@ -1,59 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Copyright The OpenTelemetry Authors
4
- #
5
- # SPDX-License-Identifier: Apache-2.0
6
- #
7
- require 'delegate'
8
-
9
- module OpenTelemetry
10
- module Instrumentation
11
- module ActionView
12
- # This is a replacement for the default Fanout notifications queue, which adds special
13
- # handling around returned context from the SpanSubscriber notification handlers.
14
- # Used together, it allows us to trace arbitrary ActiveSupport::Notifications safely.
15
- class Fanout < DelegateClass(::ActiveSupport::Notifications::Fanout)
16
- def initialize(notifier = ::ActiveSupport::Notifications::Fanout.new)
17
- super(notifier)
18
- end
19
-
20
- def start(name, id, payload)
21
- listeners_for(name).map do |s|
22
- result = [s]
23
- state = s.start(name, id, payload)
24
- if state.is_a?(Array) && state[0].is_a?(OpenTelemetry::Trace::Span) && state[1] # rubocop:disable Style/IfUnlessModifier
25
- result << state
26
- end
27
-
28
- result
29
- end
30
- end
31
-
32
- def finish(name, id, payload, listeners = listeners_for(name))
33
- listeners.each do |(s, arr)|
34
- span, token = arr
35
- if span.is_a?(OpenTelemetry::Trace::Span) && token
36
- s.finish(
37
- name,
38
- id,
39
- payload.merge(
40
- __opentelemetry_span: span,
41
- __opentelemetry_ctx_token: token
42
- )
43
- )
44
- else
45
- s.finish(name, id, payload)
46
- end
47
- end
48
- end
49
-
50
- def listeners_for(name)
51
- listeners = super
52
- listeners.sort_by do |l|
53
- l.instance_variable_get(:@delegate).is_a?(SpanSubscriber) ? -1 : 1
54
- end
55
- end
56
- end
57
- end
58
- end
59
- end
@@ -1,89 +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 ActionView
10
- # The SpanSubscriber is a special ActiveSupport::Notification subscription
11
- # handler which turns notifications into generic spans, taking care to handle
12
- # context appropriately.
13
- class SpanSubscriber
14
- ALWAYS_VALID_PAYLOAD_TYPES = [TrueClass, FalseClass, String, Numeric, Symbol].freeze
15
-
16
- def initialize(name:, tracer:)
17
- @span_name = name.split('.')[0..1].reverse.join(' ').freeze
18
- @tracer = tracer
19
- end
20
-
21
- def start(_name, _id, payload)
22
- span = @tracer.start_span(@span_name, kind: :internal)
23
- token = OpenTelemetry::Context.attach(
24
- OpenTelemetry::Trace.context_with_span(span)
25
- )
26
-
27
- [span, token]
28
- end
29
-
30
- def finish(_name, _id, payload) # rubocop:disable Metrics/AbcSize
31
- span = payload.delete(:__opentelemetry_span)
32
- token = payload.delete(:__opentelemetry_ctx_token)
33
- return unless span && token
34
-
35
- payload = transform_payload(payload)
36
- attrs = payload.map do |k, v|
37
- [k.to_s, sanitized_value(v)] if valid_payload_key?(k) && valid_payload_value?(v)
38
- end
39
- span.add_attributes(attrs.compact.to_h)
40
-
41
- if (e = payload[:exception_object])
42
- span.record_exception(e)
43
- span.status = OpenTelemetry::Trace::Status.error("Unhandled exception of type: #{e.class}")
44
- end
45
-
46
- span.finish
47
- OpenTelemetry::Context.detach(token)
48
- end
49
-
50
- private
51
-
52
- def instrumentation_config
53
- ActionView::Instrumentation.instance.config
54
- end
55
-
56
- def transform_payload(payload)
57
- return payload if instrumentation_config[:notification_payload_transform].nil?
58
-
59
- instrumentation_config[:notification_payload_transform].call(payload)
60
- end
61
-
62
- def valid_payload_key?(key)
63
- %i[exception exception_object].none?(key) && instrumentation_config[:disallowed_notification_payload_keys].none?(key)
64
- end
65
-
66
- def valid_payload_value?(value)
67
- if value.is_a?(Array)
68
- return true if value.empty?
69
-
70
- value.map(&:class).uniq.size == 1 && ALWAYS_VALID_PAYLOAD_TYPES.any? { |t| value.first.is_a?(t) }
71
- else
72
- ALWAYS_VALID_PAYLOAD_TYPES.any? { |t| value.is_a?(t) }
73
- end
74
- end
75
-
76
- # We'll accept symbols as values, but stringify them; and we'll stringify symbols within an array.
77
- def sanitized_value(value)
78
- if value.is_a?(Array)
79
- value.map { |v| v.is_a?(Symbol) ? v.to_s : v }
80
- elsif value.is_a?(Symbol)
81
- value.to_s
82
- else
83
- value
84
- end
85
- end
86
- end
87
- end
88
- end
89
- end