{{ message }}
fix(core): Defer TwP sampling by reading trace state from the scope#21549
Open
andreiborza wants to merge 5 commits into
Open
fix(core): Defer TwP sampling by reading trace state from the scope#21549andreiborza wants to merge 5 commits into
andreiborza wants to merge 5 commits into
Conversation
In Tracing-without-Performance (spans disabled), a root placeholder previously froze a negative sampling decision in the DSC, which suppressed downstream sampling instead of leaving the decision to a performance-enabled service further along the trace. The scope is the source of truth for a TwP placeholder's trace state: - `getTraceData` reads the sampling decision from the scope (deferred for a new trace, the upstream decision for a continued trace) while keeping the placeholder's stable span id, so the outgoing `sentry-trace` header omits the flag instead of asserting `-0`. - `getDynamicSamplingContextFromSpan` resolves a placeholder's DSC from its captured scope (continued traces keep the incoming DSC; new traces derive it from the client). A new (head-of-trace) TwP trace does not stamp a local `transaction` in its DSC; continued traces still propagate the upstream decision and DSC. No DSC is written to the scope at span start, preserving the browser's "scope stays DSC-free between navigations" behavior.
Contributor
size-limit report 📦
|
Sorry, something went wrong.
mydea
reviewed
Jun 15, 2026
mydea
reviewed
Jun 15, 2026
mydea
reviewed
Jun 15, 2026
mydea
reviewed
Jun 15, 2026
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 6a7c654. Configure here.
Sorry, something went wrong.
mydea
reviewed
Jun 16, 2026
JPeer264
reviewed
Jun 16, 2026
JPeer264
left a comment
Member
There was a problem hiding this comment.
Actually pretty smart to put that into the DSC into the scope for TwP.
Not approving just yet because of my comment and the Symbol comment of Francesco.
Sorry, something went wrong.
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
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.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.

In Tracing-without-Performance (spans disabled), a root placeholder previously froze a negative sampling decision in the DSC, which suppressed downstream sampling instead of leaving the decision to a performance-enabled service further along the trace.
The scope is the source of truth for a TwP placeholder's trace state:
getTraceDatareads the sampling decision from the scope (deferred for a new trace, the upstream decision for acontinued trace), so the outgoing
sentry-traceheader omits the flag instead of asserting-0. The span id comes from the scope'spropagationSpanId(a fresh id is generated when the scope has none).getDynamicSamplingContextFromSpanresolves a placeholder's DSC from its captured scope (continued traces keep the incoming DSC; new traces derive it from the client).The scope is only consulted for genuine TwP placeholders. A non-recording span in tracing mode, the child of an unsampled span, or an ignored span carries an explicit negative decision and keeps propagating
-0viaspanToTraceHeader.A new (head-of-trace) TwP trace does not stamp a local
transactionin its DSC; continued traces still propagate the upstream decision and DSC.No DSC is written to the scope at span start, preserving the browser's "scope stays DSC-free between navigations" behavior.
This is an alternative to #21406