fix(core): [Session based Traces for Mobile 2] Keep transaction baggage mutable#5402
Draft
adinauer wants to merge 3 commits into
Draft
Conversation
Copying session trace baggage for a transaction now creates mutable baggage so the transaction can populate DSC fields even if the ambient session baggage was already frozen by an earlier outgoing request. Co-Authored-By: Claude <[email protected]>
📲 Install BuildsAndroid
|
This was referenced May 11, 2026
Contributor
Performance metrics 🚀
|
Only remap root transactions onto the session propagation context when a session is currently active. This avoids reusing the ambient scope trace when session trace lifecycle is enabled before a session starts. Co-Authored-By: Claude <[email protected]>
This reverts commit d31251a.
8 tasks
buenaflor
approved these changes
May 13, 2026
Contributor
buenaflor
left a comment
There was a problem hiding this comment.
looks good, only got a question about an additional test case
Comment on lines
+1869
to
+1888
| @Test | ||
| fun `session trace transaction baggage is populated after scope baggage is frozen`() { | ||
| val scopes = generateScopes { | ||
| it.isEnableSessionTraceLifecycle = true | ||
| it.release = "1.0.0" | ||
| it.environment = "production" | ||
| } | ||
|
|
||
| scopes.startSession() | ||
|
|
||
| val sessionTraceId = AtomicReference<SentryId>() | ||
| val sessionSampleRand = AtomicReference<Double>() | ||
| val headersWithoutTransaction = | ||
| TracingUtils.traceIfAllowed(scopes, "https://sentry.io/hello", emptyList(), null) | ||
| assertNotNull(headersWithoutTransaction) | ||
| scopes.configureScope { scope -> | ||
| sessionTraceId.set(scope.propagationContext.traceId) | ||
| sessionSampleRand.set(scope.propagationContext.sampleRand) | ||
| assertFalse(scope.propagationContext.baggage!!.isMutable) | ||
| } |
Contributor
There was a problem hiding this comment.
should we also add a test that tracesSampler sampleRates are respected? not sure if that should be here or another PR
e.g tracesSampler: if transaction A: 0.8 else 0.2
- then a request associated with transaction A propagates transaction A sample_rate (0.8) in the baggage
- then a request associated with transaction B propagates transaction B sample_rate (0.2) in the baggage
8 tasks
adinauer
commented
May 13, 2026
| baggage.thirdPartyHeader, | ||
| baggage.mutable, | ||
| baggage.shouldFreeze, | ||
| true, |
Member
Author
There was a problem hiding this comment.
Undoing this "unfreeze" change in #5429 again since we can rely on Baggage still being mutable in head of trace scenario when creating a transaction.
8 tasks
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
Add this suggestion to a batch that can be applied as a single commit.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.Add this suggestion to a batch that can be applied as a single commit.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.Suggestion cannot be applied right now. Please check back later.
PR Stack (Session based Traces for Mobile)
📜 Description
Keeps transaction baggage mutable when remapping a root transaction onto the current session trace. This lets each transaction populate its own DSC fields even if the ambient session propagation baggage was already frozen by an earlier outgoing request without an active transaction.
Adds regression coverage for:
💡 Motivation and Context
Session trace lifecycle can freeze ambient scope baggage before any transaction starts. If a later transaction reuses that frozen baggage directly, outgoing transaction propagation can miss transaction-specific DSC such as
sentry-transaction,sentry-sampled,sentry-sample_rate, andsentry-sample_rand.This keeps the session trace id and sample rand while allowing each remapped transaction to complete its own outgoing baggage.
💚 How did you test it?
./gradlew spotlessApply apiDump./gradlew :sentry:test --tests 'io.sentry.BaggageTest' --tests 'io.sentry.ScopesTest.session trace transaction baggage is populated after scope baggage is frozen'📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps
Continue the Session based Traces for Mobile stack.
#skip-changelog