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

feat!: Custom ActiveSupport Span Names #1014

Merged

Conversation

arielvalentin
Copy link
Collaborator

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 #957

@@ -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
Copy link
Contributor

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?

Copy link
Collaborator Author

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
Copy link
Contributor

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?

Copy link
Collaborator Author

@arielvalentin arielvalentin Jun 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arielvalentin arielvalentin force-pushed the as-support-format-span-name branch 2 times, most recently from 6aa3ec0 to a649c5a Compare June 20, 2024 19:36
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
@arielvalentin
Copy link
Collaborator Author

gentle ping @open-telemetry/ruby-contrib-approvers

@arielvalentin arielvalentin merged commit e14d6b0 into open-telemetry:main Jun 24, 2024
54 checks passed
@github-actions github-actions bot mentioned this pull request Jun 24, 2024
@arielvalentin arielvalentin deleted the as-support-format-span-name branch June 24, 2024 16:24
arielvalentin added a commit to arielvalentin/opentelemetry-ruby-contrib that referenced this pull request Jun 24, 2024
It also allows users to rollback to legacy span name format.

Follow up to open-telemetry#1014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants