-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(node): Update scope transactionName
in http and express instrumentations
#11434
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
Conversation
/** Update the span with data we need. */ | ||
function _updateSpan(span: Span): void { | ||
addOriginToSpan(span, 'auto.http.otel.http'); | ||
} |
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.
slight refactor (can also revert if reviewers prefer): This function is just a one-liner, being called once, so I inlined it.
@@ -0,0 +1,29 @@ | |||
const { loggingTransport } = require('@sentry-internal/node-integration-tests'); |
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.
Side note: This is not the only integration test that covers event.transaction
values in Express. There are a bunch more but they didn't change because changes 1 and 3 (see description) cancel each other out. Which IMO is good news :D
// type cast b/c Otel unfortunately types info.request as any :( | ||
const req = info.request as { method?: string }; | ||
const method = req.method ? req.method.toUpperCase() : 'GET'; | ||
getIsolationScope().setTransactionName(`${method} ${info.route}`); |
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 guess there's also a case to be made that this should be set on the current scope instead.
Rationale: 2 nested request handlers -> current scope would set the transactionName correctly whereas isolation scope would outlive the inner handler
…mentations (getsentry#11434) Concrete changes: 1. `addRequestDataToEvent` no longer applies its transaction name to _non-transaction_ events 2. Http instrumentation sets the isolation scope's `transactionName` in the Otel `requestHook` to the unparameterized request URL path (w/o query params or fragments). 3. Express instrumentation sets the isolation scope's `transactionName` in the Otel `spanName` hook to a parameterized route, once a request handler span (e.g. `app.get(...)`) is created. 4. As a consequence of the above, non-transaction events now get assigned `event.transaction` correctly from the scopes.
This PR now adds scope
transactionName
updating to the first Node-based instrumentations - the base http instrumentation and the express instrumentation. Furthermore, this PR also disables settingevent.transaction
in ouraddRequestDataToEvent
function (or integration) on non-transaction events. This is in line with what we did in #10991, just that it only concerns server SDKs.Concrete changes:
addRequestDataToEvent
no longer applies its transaction name to non-transaction eventstransactionName
in the OtelrequestHook
to the unparameterized request URL path (w/o query params or fragments).transactionName
in the OtelspanName
hook to a parameterized route, once a request handler span (e.g.app.get(...)
) is created.event.transaction
correctly from the scopes.I chose setting the transactionName on the isolation scope instead of the current scope because in Node-land, this should give users a good way of manually overriding the name via
getCurrentScope.setTransactionName
if they chose to do so. Otherwise, I think it's fine to keep the "good", parameterized name for the entire request handling time but open to counter arguments :)ref #10846