opentelemetry-instrumentation-action_view 0.1.2 → 0.1.3
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 +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +16 -0
- data/lib/opentelemetry/instrumentation/action_view/instrumentation.rb +0 -1
- data/lib/opentelemetry/instrumentation/action_view/railtie.rb +2 -5
- data/lib/opentelemetry/instrumentation/action_view/span_subscriber.rb +24 -2
- data/lib/opentelemetry/instrumentation/action_view/version.rb +1 -1
- metadata +4 -5
- data/lib/opentelemetry/instrumentation/action_view/fanout.rb +0 -59
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 62bb2b892d835cb28873c5dd2e5a682ef3a041853a05a8cad2e697c5d4e55d55
|
4
|
+
data.tar.gz: 3033a19d95b625d9503344aa907d5fdd51ef8275c7f3a9e9978aee3eafd6416f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ebd63ee4576b464dccce7fe51abd02c3b3eb86411a1d4b709e39c2590c0d09999ae8dc5f63c551be1f4a4003ec89dd1972c58eb29138d175312a6839a66fe5e
|
7
|
+
data.tar.gz: 54cd21b7714c1d78790eed3ab1627b6eaf5142f26016b3e3dbd57083adda41466500effbbb5170d5693fa190d89fdc4df9b428ba3a2e507639101126ef5fd6f3
|
data/CHANGELOG.md
CHANGED
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`.
|
@@ -15,17 +15,14 @@ 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
|
23
19
|
SUBSCRIPTIONS.each do |subscription_name|
|
24
20
|
subscriber = OpenTelemetry::Instrumentation::ActionView::SpanSubscriber.new(
|
25
21
|
name: subscription_name,
|
26
22
|
tracer: ActionView::Instrumentation.instance.tracer
|
27
23
|
)
|
28
|
-
|
24
|
+
|
25
|
+
::OpenTelemetry::Instrumentation::ActionView.subscribe(subscription_name, subscriber)
|
29
26
|
end
|
30
27
|
end
|
31
28
|
end
|
@@ -6,10 +6,27 @@
|
|
6
6
|
|
7
7
|
module OpenTelemetry
|
8
8
|
module Instrumentation
|
9
|
+
# rubocop:disable Style/Documentation
|
9
10
|
module ActionView
|
10
11
|
# The SpanSubscriber is a special ActiveSupport::Notification subscription
|
11
12
|
# handler which turns notifications into generic spans, taking care to handle
|
12
13
|
# context appropriately.
|
14
|
+
|
15
|
+
# A very hacky way to make sure that OpenTelemetry::Instrumentation::ActionView::SpanSubscriber
|
16
|
+
# gets invoked first
|
17
|
+
def self.subscribe(pattern = nil, callable = nil)
|
18
|
+
ActiveSupport::Notifications.subscribe(pattern, callable)
|
19
|
+
::ActiveSupport::Notifications.notifier.synchronize do
|
20
|
+
if ::Rails::VERSION::MAJOR == 6
|
21
|
+
s = ::ActiveSupport::Notifications.notifier.instance_variable_get(:@string_subscribers)[pattern].pop
|
22
|
+
::ActiveSupport::Notifications.notifier.instance_variable_get(:@string_subscribers)[pattern].unshift(s)
|
23
|
+
else
|
24
|
+
s = ::ActiveSupport::Notifications.notifier.instance_variable_get(:@subscribers).pop
|
25
|
+
::ActiveSupport::Notifications.notifier.instance_variable_get(:@subscribers).unshift(s)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
13
30
|
class SpanSubscriber
|
14
31
|
ALWAYS_VALID_PAYLOAD_TYPES = [TrueClass, FalseClass, String, Numeric, Symbol].freeze
|
15
32
|
|
@@ -18,16 +35,20 @@ module OpenTelemetry
|
|
18
35
|
@tracer = tracer
|
19
36
|
end
|
20
37
|
|
21
|
-
def start(
|
38
|
+
def start(name, id, payload)
|
22
39
|
span = @tracer.start_span(@span_name, kind: :internal)
|
23
40
|
token = OpenTelemetry::Context.attach(
|
24
41
|
OpenTelemetry::Trace.context_with_span(span)
|
25
42
|
)
|
43
|
+
payload.merge!(
|
44
|
+
__opentelemetry_span: span,
|
45
|
+
__opentelemetry_ctx_token: token
|
46
|
+
)
|
26
47
|
|
27
48
|
[span, token]
|
28
49
|
end
|
29
50
|
|
30
|
-
def finish(
|
51
|
+
def finish(name, id, payload) # rubocop:disable Metrics/AbcSize
|
31
52
|
span = payload.delete(:__opentelemetry_span)
|
32
53
|
token = payload.delete(:__opentelemetry_ctx_token)
|
33
54
|
return unless span && token
|
@@ -86,4 +107,5 @@ module OpenTelemetry
|
|
86
107
|
end
|
87
108
|
end
|
88
109
|
end
|
110
|
+
# rubocop:enable Style/Documentation
|
89
111
|
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.
|
4
|
+
version: 0.1.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: 2021-
|
11
|
+
date: 2021-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: opentelemetry-api
|
@@ -206,7 +206,6 @@ files:
|
|
206
206
|
- lib/opentelemetry-instrumentation-action_view.rb
|
207
207
|
- lib/opentelemetry/instrumentation.rb
|
208
208
|
- lib/opentelemetry/instrumentation/action_view.rb
|
209
|
-
- lib/opentelemetry/instrumentation/action_view/fanout.rb
|
210
209
|
- lib/opentelemetry/instrumentation/action_view/instrumentation.rb
|
211
210
|
- lib/opentelemetry/instrumentation/action_view/railtie.rb
|
212
211
|
- lib/opentelemetry/instrumentation/action_view/span_subscriber.rb
|
@@ -215,10 +214,10 @@ homepage: https://github.com/open-telemetry/opentelemetry-ruby
|
|
215
214
|
licenses:
|
216
215
|
- Apache-2.0
|
217
216
|
metadata:
|
218
|
-
changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-instrumentation-action_view/v0.1.
|
217
|
+
changelog_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-instrumentation-action_view/v0.1.3/file.CHANGELOG.html
|
219
218
|
source_code_uri: https://github.com/open-telemetry/opentelemetry-ruby/tree/main/instrumentation/action_view
|
220
219
|
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.
|
220
|
+
documentation_uri: https://open-telemetry.github.io/opentelemetry-ruby/opentelemetry-instrumentation-action_view/v0.1.3
|
222
221
|
post_install_message:
|
223
222
|
rdoc_options: []
|
224
223
|
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
|