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

feat(browser): Update propagationContext on spanEnd to keep trace consistent #11631

Merged
merged 4 commits into from
Apr 17, 2024

Conversation

Lms24
Copy link
Member

@Lms24 Lms24 commented Apr 16, 2024

As spec'd out in #11599 and agreed upon in internal discussions, a trace should to stay consistent over the entire time span of one route. Therefore, when the initial pageload or navigation span ends, we update the scope's propagation context to keep span-specific attributes like the sampled decision and the dynamic sampling context on the scope's propagation context, even after the transaction has ended.

This ensures that the trace data is consistent for the entire duration of the route. Subsequent navigations will reset the propagation context (see #11377).

cc @cleptric

ref #11599

Copy link
Contributor

github-actions bot commented Apr 16, 2024

size-limit report 📦

Path Size
@sentry/browser 21.67 KB (0%)
@sentry/browser (incl. Tracing) 31.46 KB (+0.23% 🔺)
@sentry/browser (incl. Tracing, Replay) 66.79 KB (+0.12% 🔺)
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 60.19 KB (+0.13% 🔺)
@sentry/browser (incl. Tracing, Replay with Canvas) 70.62 KB (+0.11% 🔺)
@sentry/browser (incl. Tracing, Replay, Feedback) 80.5 KB (+0.11% 🔺)
@sentry/browser (incl. Feedback) 35.25 KB (0%)
@sentry/browser (incl. Feedback, Feedback Modal) 35.25 KB (0%)
@sentry/browser (incl. Feedback, Feedback Modal, Feedback Screenshot) 37.28 KB (0%)
@sentry/browser (incl. sendFeedback) 26.46 KB (0%)
@sentry/react 24.35 KB (0%)
@sentry/react (incl. Tracing) 34.37 KB (+0.22% 🔺)
@sentry/vue 25.2 KB (0%)
@sentry/vue (incl. Tracing) 33.18 KB (+0.22% 🔺)
@sentry/svelte 21.79 KB (0%)
CDN Bundle 24.03 KB (0%)
CDN Bundle (incl. Tracing) 32.76 KB (+0.25% 🔺)
CDN Bundle (incl. Tracing, Replay) 66.4 KB (+0.11% 🔺)
CDN Bundle (incl. Tracing, Replay, Feedback) 82.6 KB (+0.1% 🔺)
CDN Bundle - uncompressed 70.86 KB (0%)
CDN Bundle (incl. Tracing) - uncompressed 97.59 KB (+0.24% 🔺)
CDN Bundle (incl. Tracing, Replay) - uncompressed 207.25 KB (+0.11% 🔺)
@sentry/nextjs (client) 33.7 KB (+0.23% 🔺)
@sentry/sveltekit (client) 31.96 KB (+0.23% 🔺)
@sentry/node 153.46 KB (0%)

@Lms24 Lms24 force-pushed the lms/feat-browser-update-propagationContext-spanEnd branch from 4fc17db to 7197b8c Compare April 16, 2024 14:39

const newPropagationContext = {
...oldPropagationContext,
sampled: oldPropagationContext.sampled !== undefined ? oldPropagationContext.sampled : spanIsSampled(span),
Copy link
Member

Choose a reason for hiding this comment

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

l/m: Not 100% sure, but maybe it would be safer to pick this from the DSC, to ensure this is aligned? So something like this:

const dsc = oldPropagationContext.dsc || getDynamicSamplingContextFromSpan(span);
const dscSampled = dsc.sampled === 'true' ? true : dsc.sampled === 'false' : false : undefined;
const sampled = oldPropagationContext.sampled !== undefined ? oldPropagationContext.sampled : dscSampled;

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, can change it! I'm just wondering about a concrete scenario where these two might diverge; like spanIsSampled returning false while the dsc.sampled being true or undefined.

Copy link
Member

Choose a reason for hiding this comment

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

Please do not use any values from the DSC in the SDK. This has potential to cause a lot of issues later on.

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay, so we quickly discussed this in person with @cleptric and settled on updating propagationContext.sampled from the propagation context and spanIsSampled instead of the DSC. The reason is that there are talks around removing sampled from the DSC again because it's (likely) unused in ingest/product.

Both of the approaches currently lead to the same outcome, as demonstrated by the integration tests but it's safer in this case to read from propagationContext (i.e. sentry-trace) instead of DSC/baggage.

fix incorrect `baggage` header in <meta> integration test
@Lms24 Lms24 marked this pull request as ready for review April 17, 2024 10:27
@Lms24 Lms24 self-assigned this Apr 17, 2024
@Lms24 Lms24 merged commit cfcd226 into develop Apr 17, 2024
90 of 91 checks passed
@Lms24 Lms24 deleted the lms/feat-browser-update-propagationContext-spanEnd branch April 17, 2024 11:39
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.

None yet

4 participants