feat(node): Update scope transactionName in http and express instrumentations#11434
Merged
feat(node): Update scope transactionName in http and express instrumentations#11434
transactionName in http and express instrumentations#11434Conversation
Lms24
commented
Apr 5, 2024
Comment on lines
-126
to
-129
| /** Update the span with data we need. */ | ||
| function _updateSpan(span: Span): void { | ||
| addOriginToSpan(span, 'auto.http.otel.http'); | ||
| } |
Member
Author
There was a problem hiding this comment.
slight refactor (can also revert if reviewers prefer): This function is just a one-liner, being called once, so I inlined it.
Lms24
commented
Apr 5, 2024
| @@ -0,0 +1,29 @@ | |||
| const { loggingTransport } = require('@sentry-internal/node-integration-tests'); | |||
Member
Author
There was a problem hiding this comment.
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
Lms24
commented
Apr 5, 2024
| // 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}`); |
Member
Author
There was a problem hiding this comment.
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
lforst
approved these changes
Apr 5, 2024
cadesalaberry
pushed a commit
to cadesalaberry/sentry-javascript
that referenced
this pull request
Apr 19, 2024
…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 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR now adds scope
transactionNameupdating to the first Node-based instrumentations - the base http instrumentation and the express instrumentation. Furthermore, this PR also disables settingevent.transactionin ouraddRequestDataToEventfunction (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:
addRequestDataToEventno longer applies its transaction name to non-transaction eventstransactionNamein the OtelrequestHookto the unparameterized request URL path (w/o query params or fragments).transactionNamein the OtelspanNamehook to a parameterized route, once a request handler span (e.g.app.get(...)) is created.event.transactioncorrectly 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.setTransactionNameif 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