-
Notifications
You must be signed in to change notification settings - Fork 181
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
feat!: Custom ActiveSupport Span Names #1014
feat!: Custom ActiveSupport Span Names #1014
Conversation
@@ -19,11 +21,13 @@ def self.subscribe( | |||
tracer, | |||
pattern, | |||
notification_payload_transform = nil, | |||
disallowed_notification_payload_keys = [] | |||
disallowed_notification_payload_keys = nil, | |||
span_name_formatter = nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if the intent might be more clear if we defaulted this to a passthrough rather than nil
? Something like:
PASSTHROUGH_NAME_FORMATTER = =>(name) { name.dup.freeze }
# …
span_name_formatter = PASSTHROUGH_NAME_FORMATTER
Maybe it doesn't matter. Six of one, half a dozen of the other, as they say?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think even though it is symmetric, I am going choose to minimize allocations.
# | ||
# It wraps the user supplied formatter in a rescue block and returns the original name if a StandardError is raised by the formatter | ||
def safe_span_name_for(span_name_formatter, name) | ||
span_name_formatter&.call(name) || name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're going to go this route, should we #dup#freeze
the name
that we fall back to for consistency with how the legacy formatter now works?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added dup.freeze
to the result of the method call.
6aa3ec0
to
a649c5a
Compare
The current implementation of ActiveSupport instrumentation sets the span name to the reverse tokenized name, e.g. `render_template.action_view` is converted to `action_view render_template` This default behavior can sometimes seem counter intuitive for users who use ActiveSupport Notifications to instrument their own code or users who are familiar with Rails instrumentation names. This change does a few things to address the issues listed above: 1. Uses the notification name by default as oppossed to the legacy span name 2. Allows users to provide a custom span name formatter lambda 3. Provides a proc with backward compatible span name formatter `OpenTelemetry::Instrumentation::ActiveSupport::LEGACY_NAME_FORMATTER` See open-telemetry#957
9d7f17f
to
c304028
Compare
gentle ping @open-telemetry/ruby-contrib-approvers |
It also allows users to rollback to legacy span name format. Follow up to open-telemetry#1014
The current implementation of ActiveSupport instrumentation sets the span name to the reverse tokenized name, e.g.
render_template.action_view
is converted toaction_view render_template
This default behavior can sometimes seem counter intuitive for users who use ActiveSupport Notifications to instrument their own code or users who are familiar with Rails instrumentation names.
This change does a few things to address the issues listed above:
OpenTelemetry::Instrumentation::ActiveSupport::LEGACY_NAME_FORMATTER
See #957