-
Notifications
You must be signed in to change notification settings - Fork 226
fix: action_pack always assuming sdk spans #1562
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
Merged
robertlaurin
merged 1 commit into
open-telemetry:main
from
robertlaurin:fix-sdk-span-dep
Jun 16, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,9 @@ def initialize(config) | |
| # @param payload [Hash] the payload passed as a method argument | ||
| # @return [Hash] the payload passed as a method argument | ||
| def start(_name, _id, payload) | ||
| span = OpenTelemetry::Instrumentation::Rack.current_span | ||
| return unless span.recording? | ||
|
|
||
| request = payload[:request] | ||
| # It seems that there are cases in Rails functional tests where it bypasses the routing system and the `action_dispatch.route_uri_pattern` header not being set. | ||
| # Our Test suite executes the routing system so we are unable to recreate this error case. | ||
|
|
@@ -36,22 +39,18 @@ def start(_name, _id, payload) | |
| attributes[OpenTelemetry::SemanticConventions::Trace::HTTP_ROUTE] = http_route if http_route | ||
| attributes[OpenTelemetry::SemanticConventions::Trace::HTTP_TARGET] = request.filtered_path if request.filtered_path != request.fullpath | ||
|
|
||
| span = OpenTelemetry::Instrumentation::Rack.current_span | ||
| span_name = if @span_naming == :semconv | ||
| if http_route | ||
| if @span_naming == :semconv | ||
| span.name = if http_route | ||
| "#{request.method} #{http_route}" | ||
| else | ||
| "#{request.method} /#{payload.dig(:params, :controller)}/#{payload.dig(:params, :action)}" | ||
| end | ||
| # If there is an exception we want to keep the original span name | ||
| # so it is easier to see where the request was routed to. | ||
| elsif request.env['action_dispatch.exception'] | ||
| span.name | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. API spans have a setter, but not a getter for |
||
| else | ||
| "#{payload[:controller]}##{payload[:action]}" | ||
| end | ||
| # If there is an exception we want to keep the original span name | ||
| # so it is easier to see where the request was routed to. | ||
| elsif !request.env['action_dispatch.exception'] | ||
| span.name = "#{payload[:controller]}##{payload[:action]}" | ||
| end | ||
|
|
||
| span.name = span_name | ||
| span.add_attributes(attributes) | ||
| rescue StandardError => e | ||
| OpenTelemetry.handle_error(exception: e) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should we skip this entire logic unless
span.recording??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.
Yeah, that's a good improvement to make. Pushed up that change.