Skip to content

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

Merged
merged 2 commits into from
Apr 8, 2024

Conversation

Lms24
Copy link
Member

@Lms24 Lms24 commented Apr 4, 2024

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 setting event.transaction in our addRequestDataToEvent 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:

  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.

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

Comment on lines -126 to -129
/** Update the span with data we need. */
function _updateSpan(span: Span): void {
addOriginToSpan(span, 'auto.http.otel.http');
}
Copy link
Member Author

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.

@Lms24 Lms24 marked this pull request as ready for review April 5, 2024 08:58
@Lms24 Lms24 requested review from mydea, lforst and AbhiPrasad April 5, 2024 08:58
@@ -0,0 +1,29 @@
const { loggingTransport } = require('@sentry-internal/node-integration-tests');
Copy link
Member Author

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}`);
Copy link
Member Author

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

@Lms24 Lms24 merged commit 83f7cce into develop Apr 8, 2024
@Lms24 Lms24 deleted the lms/feat-node-update-scope-transactionName branch April 8, 2024 11:12
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.
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.

2 participants