Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ActionView Support Legacy Formats #1134

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

module OpenTelemetry
module Instrumentation
# Contains the OpenTelemetry instrumentation for the ActionView gem
# (see OpenTelemetry::Instrumentation::ActionView::Instrumentation)
module ActionView
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,42 @@
module OpenTelemetry
module Instrumentation
module ActionView
# The Instrumentation class contains logic to detect and install the ActionView instrumentation
# The {OpenTelemetry::Instrumentation::ActionView::Instrumentation} class contains logic to detect and install the ActionView instrumentation
#
# Installation and configuration of this instrumentation is done within the
# {https://www.rubydoc.info/gems/opentelemetry-sdk/OpenTelemetry/SDK#configure-instance_method OpenTelemetry::SDK#configure}
# block, calling {https://www.rubydoc.info/gems/opentelemetry-sdk/OpenTelemetry%2FSDK%2FConfigurator:use use()}
# or {https://www.rubydoc.info/gems/opentelemetry-sdk/OpenTelemetry%2FSDK%2FConfigurator:use_all use_all()}.
#
# ## Configuration keys and options
#
# ### `:disallowed_notification_payload_keys`
#
# Specifies an array of keys that should be excluded from the notification payload as span attributes.
#
# ### `:notification_payload_transform`
#
# - `proc` **default** `nil`
#
# Specifies custom proc used to extract span attributes form the notification payload.
# Use this to rename keys, extract nested values, or perform any other custom logic.
#
# ### `:legacy_span_names`
#
# - `boolean` **default** `false`
#
# Specifies whether spans names should use the legacy format where the subscription was reverse ordered and white space separated. (Ex. `action_view render_template`)
# If set to `true`, the span name will match the name of the notification itself. (Ex. `render_template.action_view`)
#
# @example An explicit default configuration
# OpenTelemetry::SDK.configure do |c|
# c.use_all({
# 'OpenTelemetry::Instrumentation::ActionView' => {
# disallowed_notification_payload_keys: [],
# legacy_span_names: true,
# },
# })
# end
class Instrumentation < OpenTelemetry::Instrumentation::Base
MINIMUM_VERSION = Gem::Version.new('6.1.0')
install do |_config|
Expand All @@ -24,6 +59,7 @@ class Instrumentation < OpenTelemetry::Instrumentation::Base

option :disallowed_notification_payload_keys, default: [], validate: :array
option :notification_payload_transform, default: nil, validate: :callable
option :legacy_span_names, default: false, validate: :boolean

private

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ class Railtie < ::Rails::Railtie
config.after_initialize do
::OpenTelemetry::Instrumentation::ActiveSupport::Instrumentation.instance.install({})

instance = ::OpenTelemetry::Instrumentation::ActionView::Instrumentation.instance
span_name_formatter = instance.config[:legacy_span_names] ? ::OpenTelemetry::Instrumentation::ActiveSupport::LEGACY_NAME_FORMATTER : nil

SUBSCRIPTIONS.each do |subscription_name|
config = ActionView::Instrumentation.instance.config
::OpenTelemetry::Instrumentation::ActiveSupport.subscribe(
ActionView::Instrumentation.instance.tracer,
instance.tracer,
subscription_name,
config[:notification_payload_transform],
config[:disallowed_notification_payload_keys]
instance.config[:notification_payload_transform],
instance.config[:disallowed_notification_payload_keys],
span_name_formatter: span_name_formatter
)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
spec.required_ruby_version = '>= 3.0'

spec.add_dependency 'opentelemetry-api', '~> 1.0'
spec.add_dependency 'opentelemetry-instrumentation-active_support', '~> 0.1'
spec.add_dependency 'opentelemetry-instrumentation-active_support', '~> 0.6'
spec.add_dependency 'opentelemetry-instrumentation-base', '~> 0.22.1'

spec.add_development_dependency 'appraisal', '~> 2.5'
Expand Down
Loading