Skip to content
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

fix(core): Fork scope if custom scope is passed to startSpan #14900

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

Lms24
Copy link
Member

@Lms24 Lms24 commented Jan 3, 2025

This PR fixes unexpected behaviour that would emerge when starting multiple spans in sequence with startSpan when passing on the same scope. Prior to this change, the second span would be started as the child span of the first one, because the span set active on the custom scope was not re-set to the parent span of the first span. The reason is that we didn't clean up or restore the previously active span because the custom scope is not forked in contrast to the current scope.

In very niche scenarios, this could furthermore lead to only the first span being sent and subsequent spans being discarded because they were being incorrectly considered a child span. Examples for this are the Sentry and CodeCov bundler plugins where we solely rely on @sentry/core and a custom client setup. In more conventional setups, using the Node (POTEL) or browser SDKs this probably would have gone unnoticed.

This PR fixes this edge case by also forking the custom scope if it is passed into startSpan. Since this has implications on the lifetime of other span modifications like setting tags, we consider this a behaviourally breaking change and will not backport it to v8. I adjusted tests to reflect the scope data lifetime. It's worth noting though, that in POTEL SDKs we already forked custom scope, so this PR further aligns behaviour.

This came up while reviewing codecov/codecov-javascript-bundler-plugins#224

@Lms24 Lms24 requested a review from mydea January 3, 2025 13:37
@Lms24 Lms24 self-assigned this Jan 3, 2025
Copy link
Contributor

github-actions bot commented Jan 3, 2025

size-limit report 📦

Path Size % Change Change
@sentry/browser 23.01 KB - -
@sentry/browser - with treeshaking flags 21.68 KB - -
@sentry/browser (incl. Tracing) 35.53 KB - -
@sentry/browser (incl. Tracing, Replay) 72.31 KB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 62.83 KB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 76.57 KB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 88.59 KB - -
@sentry/browser (incl. Feedback) 39.23 KB - -
@sentry/browser (incl. sendFeedback) 27.64 KB - -
@sentry/browser (incl. FeedbackAsync) 32.41 KB - -
@sentry/react 25.7 KB - -
@sentry/react (incl. Tracing) 38.29 KB - -
@sentry/vue 27.12 KB - -
@sentry/vue (incl. Tracing) 37.27 KB - -
@sentry/svelte 23.13 KB - -
CDN Bundle 24.28 KB - -
CDN Bundle (incl. Tracing) 35.83 KB +0.05% +17 B 🔺
CDN Bundle (incl. Tracing, Replay) 70.48 KB +0.03% +15 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 75.63 KB +0.03% +17 B 🔺
CDN Bundle - uncompressed 70.78 KB - -
CDN Bundle (incl. Tracing) - uncompressed 106.1 KB +0.02% +17 B 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 216.92 KB +0.01% +17 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 229.46 KB +0.01% +17 B 🔺
@sentry/nextjs (client) 38.42 KB - -
@sentry/sveltekit (client) 36.08 KB - -
@sentry/node 161.72 KB - -
@sentry/node - without tracing 97.48 KB - -
@sentry/aws-serverless 127.36 KB - -

View base workflow run

@Lms24 Lms24 force-pushed the lms/fix-core-restore-active-span-custom-scope branch from c864c76 to 52b10a8 Compare January 10, 2025 10:58
@Lms24 Lms24 changed the title fix(core): Restore previously active span when passing a custom scope to startSpan fix(core): Fork scope if custom scope is passed to startSpan Jan 10, 2025
@Lms24 Lms24 force-pushed the lms/fix-core-restore-active-span-custom-scope branch from 86ab776 to 162e105 Compare January 10, 2025 11:16
@Lms24
Copy link
Member Author

Lms24 commented Jan 10, 2025

cc @nicholas-codecov nothing for you to worry about (i.e. your implementation telemetry implementation will work fine with this change) but this is the fix I mentioned that would fix the missing spans in your traces without wrapping them in a forceTransaction: true span. I think it's totally fine though to continue having a wrapping span.

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.

1 participant