-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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(core): Add updateSpanName
helper function
#14291
Conversation
size-limit report 📦
|
70674de
to
c7b6718
Compare
❌ We are unable to process any of the uploaded JUnit XML files. Please ensure your files are in the right format. |
@@ -172,6 +296,26 @@ describe('descriptionForHttpMethod', () => { | |||
source: 'url', | |||
}, | |||
], | |||
[ | |||
'works with prefetch request', |
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.
This is just an additional test I added because we didn't test the condition to add .prefetch
to the op
.
...tegration-tests/suites/tracing/browserTracingIntegration/pageload-update-txn-name/subject.js
Outdated
Show resolved
Hide resolved
...-integration-tests/suites/tracing/browserTracingIntegration/pageload-update-txn-name/test.ts
Show resolved
Hide resolved
// if http.method exists, this is an http request span | ||
// eslint-disable-next-line deprecation/deprecation | ||
const httpMethod = attributes[ATTR_HTTP_REQUEST_METHOD] || attributes[SEMATTRS_HTTP_METHOD]; | ||
if (httpMethod) { | ||
return descriptionForHttpMethod({ attributes, name, kind }, httpMethod); | ||
return descriptionForHttpMethod({ attributes, name: getOriginalName(spanName, attributes), kind }, httpMethod); |
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.
m: Instead of repeating getOriginalName
, can we just do this at the very top of this method and then use this processed name everywhere below?
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 wanted to do this initially but then we'd potentially lose the inferred op
, no?
32d395d
to
5b42422
Compare
5b42422
to
1c71162
Compare
adee375
to
24e8320
Compare
Add `Sentry.updateSpanName()` to reliably update span names in OpenTelemetry environments; prevents overwrites from both OpenTelemetry HTTP instrumentation and Sentry's span inference logic; preserves custom names by marking them with 'custom' source and storing in temp field which takes precedence over the actual name and gets deleted at the end
TL;DR: This PR Adds
Sentry.updateSpanName()
to reliably update span names in OpenTelemetry environments; prevents overwrites from both OpenTelemetry HTTP instrumentation and Sentry's span inference logic; preserves custom names by marking them with 'custom' source and storing in temp field which takes precedence over the actual name and gets deleted at the end"Why not use
span.updateName()
?", the avid SDK user might ask. Here's why:In our Node SDK, most/all spans are created by OpenTelemetry instrumentation. OpenTelemetry has no concept of a transaction
source
and only stores the name of the span in theSpan
instance. Some instrumentation, most importantly,@opentelemetry/instrumentation-http
starts a span (in this case root span) and later on updates the name. In the http case, this update happens at the end of the request lifecycle. Consequently, any span name updates prior to this call, regardless of them coming from our SDK or from users, are overwritten.In addition to this limitation within Otel instrumentation, we also have our own span name, op and source inference logic which we apply when exporting the span to add Sentry-specific data (like a better span name, an op, a transaction source and additional data) to otel-generated spans. So even if Otel didn't call
updateName()
in its instrumentation, user-madeupdateName
calls to e.g. http.server spans were also overwritten by our logic.So we need some way of 1. bypassing our span inference logic and 2. ensuring a user-update span name has precedence over otel's span name updates.
1 we can achieve with setting the source attribute to
custom
and ensuring we don't change the span name if we encounter acustom
source.2 we can only achieve if we write the user-updated span name to temporary field on the span and apply it during our span name processing logic.
This is exactly what
updateSpanName
does:span.updateName()
SEMANTIC_ATTRIBUTES_SENTRY_SOURCE: 'custom
to the spanFurther changes in this PR:
parseSpanDescription
custom
inparseSpanDescription
span.updateName
has no effect on http.server spans, even if you set sourcecustom
This PR supersedes #14280 where I thought we could monkey-patch
span.updateName
directly to make updating the span name AND the source more consistent without a new top-level function. Turns out, we cannot do this because then, Otel instrumentation would also call the monkey-patched version ofupdateName
, meaning we can no longer distinguish between user-made and otel-made span name updates.