Skip to content

Conversation

@nicohrubec
Copy link
Member

@nicohrubec nicohrubec commented Nov 25, 2025

During investigation of this issue, we discovered that continueTrace does not propagate the given trace ID if it is called from within an already active span (in this instance this happened because of the already active span started by the cloudflare auto-instrumentation.

Solution: This PR resolves this behavior by setting the currently active span to undefined when forking the propagation context in continueTrace.

Tests:

  • After introducing the fix one of the @sentry/sveltekit unit tests started to fail. Not sure why this was triggered by this change, but I fixed it by setting the isSubRequest property on the event instead of the route, which seems correct to me.
  • Added a unit test in @sentry/core that calls continueTrace inside an active span and checks that the trace id is now propagated as we would expect.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 25, 2025

size-limit report 📦

Path Size % Change Change
@sentry/browser 24.8 kB - -
@sentry/browser - with treeshaking flags 23.31 kB - -
@sentry/browser (incl. Tracing) 41.54 kB - -
@sentry/browser (incl. Tracing, Profiling) 46.13 kB - -
@sentry/browser (incl. Tracing, Replay) 79.96 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 69.69 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 84.64 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 96.88 kB - -
@sentry/browser (incl. Feedback) 41.48 kB - -
@sentry/browser (incl. sendFeedback) 29.49 kB - -
@sentry/browser (incl. FeedbackAsync) 34.43 kB - -
@sentry/react 26.52 kB - -
@sentry/react (incl. Tracing) 43.74 kB - -
@sentry/vue 29.25 kB - -
@sentry/vue (incl. Tracing) 43.34 kB - -
@sentry/svelte 24.82 kB - -
CDN Bundle 27.17 kB +0.01% +1 B 🔺
CDN Bundle (incl. Tracing) 42.17 kB +0.02% +5 B 🔺
CDN Bundle (incl. Tracing, Replay) 78.7 kB +0.01% +5 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 84.16 kB +0.01% +3 B 🔺
CDN Bundle - uncompressed 79.85 kB +0.02% +13 B 🔺
CDN Bundle (incl. Tracing) - uncompressed 125.23 kB +0.02% +13 B 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 241.26 kB +0.01% +13 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 254.03 kB +0.01% +13 B 🔺
@sentry/nextjs (client) 45.96 kB - -
@sentry/sveltekit (client) 41.9 kB - -
@sentry/node-core 51.19 kB +0.01% +1 B 🔺
@sentry/node 159.24 kB - -
@sentry/node - without tracing 92.83 kB - -
@sentry/aws-serverless 108.08 kB - -

View base workflow run

@github-actions
Copy link
Contributor

github-actions bot commented Nov 25, 2025

node-overhead report 🧳

Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.

Scenario Requests/s % of Baseline Prev. Requests/s Change %
GET Baseline 8,981 - 8,775 +2%
GET With Sentry 1,696 19% 1,743 -3%
GET With Sentry (error only) 6,150 68% 6,219 -1%
POST Baseline 1,202 - 1,188 +1%
POST With Sentry 594 49% 582 +2%
POST With Sentry (error only) 1,057 88% 1,039 +2%
MYSQL Baseline 3,312 - 3,364 -2%
MYSQL With Sentry 473 14% 517 -9%
MYSQL With Sentry (error only) 2,702 82% 2,719 -1%

View base workflow run

@nicohrubec nicohrubec changed the title fix(core): continue trace should adopt the trace id even if there is … fix(core): continueTrace doesn't propagate given trace ID if active span exists Nov 25, 2025
@nicohrubec nicohrubec linked an issue Nov 26, 2025 that may be closed by this pull request
3 tasks
@nicohrubec nicohrubec self-assigned this Nov 26, 2025
@nicohrubec nicohrubec marked this pull request as ready for review November 26, 2025 11:16
Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work, thanks! (and thanks for fixing that Sveltekit test!)

// simulating a nested load call:
await sentryHandle()({
event: mockEvent({ route: { id: 'api/users/details/[id]', isSubRequest: true } }),
event: mockEvent({ route: { id: 'api/users/details/[id]' }, isSubRequest: true }),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, and very interesting that this passed beforehand 🤔 👀

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah it is! didn't investigate further though

});
});

it('works inside an active span', () => {
Copy link
Member

@Lms24 Lms24 Nov 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

l: let's find a slightly more descriptive description. Feel free to go with something else but suggestion:

Suggested change
it('works inside an active span', () => {
it('updates the propagation context when called inside an active span', () => {

Comment on lines +2056 to +2057
});
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m: Let's also add a second test that shows that when you now start another span within the continueTrace callback, it has the traceId and parentSpanId that's passed to continueTrace.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, added!

@nicohrubec nicohrubec requested a review from Lms24 November 26, 2025 16:55
Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@nicohrubec nicohrubec merged commit 98854d4 into develop Nov 27, 2025
396 of 398 checks passed
@nicohrubec nicohrubec deleted the nh/fix-traceid-continue-trace branch November 27, 2025 08:16
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.

continueTrace doesn't propagate given trace ID (@sentry/cloudflare)

3 participants