Skip to content

Commit f999e70

Browse files
feat: Use Default Span Name Format (#1039)
1 parent 39056a3 commit f999e70

File tree

4 files changed

+46
-7
lines changed

4 files changed

+46
-7
lines changed

instrumentation/action_view/lib/opentelemetry/instrumentation/action_view.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
module OpenTelemetry
1111
module Instrumentation
12-
# Contains the OpenTelemetry instrumentation for the ActionView gem
12+
# (see OpenTelemetry::Instrumentation::ActionView::Instrumentation)
1313
module ActionView
1414
end
1515
end

instrumentation/action_view/lib/opentelemetry/instrumentation/action_view/instrumentation.rb

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,42 @@
77
module OpenTelemetry
88
module Instrumentation
99
module ActionView
10-
# The Instrumentation class contains logic to detect and install the ActionView instrumentation
10+
# The {OpenTelemetry::Instrumentation::ActionView::Instrumentation} class contains logic to detect and install the ActionView instrumentation
11+
#
12+
# Installation and configuration of this instrumentation is done within the
13+
# {https://www.rubydoc.info/gems/opentelemetry-sdk/OpenTelemetry/SDK#configure-instance_method OpenTelemetry::SDK#configure}
14+
# block, calling {https://www.rubydoc.info/gems/opentelemetry-sdk/OpenTelemetry%2FSDK%2FConfigurator:use use()}
15+
# or {https://www.rubydoc.info/gems/opentelemetry-sdk/OpenTelemetry%2FSDK%2FConfigurator:use_all use_all()}.
16+
#
17+
# ## Configuration keys and options
18+
#
19+
# ### `:disallowed_notification_payload_keys`
20+
#
21+
# Specifies an array of keys that should be excluded from the notification payload as span attributes.
22+
#
23+
# ### `:notification_payload_transform`
24+
#
25+
# - `proc` **default** `nil`
26+
#
27+
# Specifies custom proc used to extract span attributes form the notification payload.
28+
# Use this to rename keys, extract nested values, or perform any other custom logic.
29+
#
30+
# ### `:legacy_span_names`
31+
#
32+
# - `boolean` **default** `false`
33+
#
34+
# Specifies whether spans names should use the legacy format where the subscription was reverse ordered and white space separated. (Ex. `action_view render_template`)
35+
# If set to `true`, the span name will match the name of the notification itself. (Ex. `render_template.action_view`)
36+
#
37+
# @example An explicit default configuration
38+
# OpenTelemetry::SDK.configure do |c|
39+
# c.use_all({
40+
# 'OpenTelemetry::Instrumentation::ActionView' => {
41+
# disallowed_notification_payload_keys: [],
42+
# legacy_span_names: true,
43+
# },
44+
# })
45+
# end
1146
class Instrumentation < OpenTelemetry::Instrumentation::Base
1247
MINIMUM_VERSION = Gem::Version.new('6.1.0')
1348
install do |_config|
@@ -24,6 +59,7 @@ class Instrumentation < OpenTelemetry::Instrumentation::Base
2459

2560
option :disallowed_notification_payload_keys, default: [], validate: :array
2661
option :notification_payload_transform, default: nil, validate: :callable
62+
option :legacy_span_names, default: false, validate: :boolean
2763

2864
private
2965

instrumentation/action_view/lib/opentelemetry/instrumentation/action_view/railtie.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,16 @@ class Railtie < ::Rails::Railtie
1919
config.after_initialize do
2020
::OpenTelemetry::Instrumentation::ActiveSupport::Instrumentation.instance.install({})
2121

22+
instance = ::OpenTelemetry::Instrumentation::ActionView::Instrumentation.instance
23+
span_name_formatter = instance.config[:legacy_span_names] ? ::OpenTelemetry::Instrumentation::ActiveSupport::LEGACY_NAME_FORMATTER : nil
24+
2225
SUBSCRIPTIONS.each do |subscription_name|
23-
config = ActionView::Instrumentation.instance.config
2426
::OpenTelemetry::Instrumentation::ActiveSupport.subscribe(
25-
ActionView::Instrumentation.instance.tracer,
27+
instance.tracer,
2628
subscription_name,
27-
config[:notification_payload_transform],
28-
config[:disallowed_notification_payload_keys]
29+
instance.config[:notification_payload_transform],
30+
instance.config[:disallowed_notification_payload_keys],
31+
span_name_formatter: span_name_formatter
2932
)
3033
end
3134
end

instrumentation/action_view/opentelemetry-instrumentation-action_view.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
2626
spec.required_ruby_version = '>= 3.0'
2727

2828
spec.add_dependency 'opentelemetry-api', '~> 1.0'
29-
spec.add_dependency 'opentelemetry-instrumentation-active_support', '~> 0.1'
29+
spec.add_dependency 'opentelemetry-instrumentation-active_support', '~> 0.6'
3030
spec.add_dependency 'opentelemetry-instrumentation-base', '~> 0.22.1'
3131

3232
spec.add_development_dependency 'appraisal', '~> 2.5'

0 commit comments

Comments
 (0)