-
-
Notifications
You must be signed in to change notification settings - Fork 468
fix(core): [Session based Traces for Mobile 2] Keep transaction baggage mutable #5402
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
Draft
adinauer
wants to merge
3
commits into
ref/remove-propagation-context-mode
Choose a base branch
from
fix/session-based-traces-mobile-transaction-baggage
base: ref/remove-propagation-context-mode
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+71
−4
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ import io.sentry.test.createTestScopes | |
| import io.sentry.test.initForTest | ||
| import io.sentry.util.HintUtils | ||
| import io.sentry.util.StringUtils | ||
| import io.sentry.util.TracingUtils | ||
| import java.io.File | ||
| import java.nio.file.Files | ||
| import java.util.Queue | ||
|
|
@@ -1865,6 +1866,47 @@ class ScopesTest { | |
| assertNull(transaction.root.spanContext.parentSpanId) | ||
| } | ||
|
|
||
| @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) | ||
| } | ||
|
Comment on lines
+1869
to
+1888
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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
|
||
|
|
||
| val firstTransaction = | ||
| scopes.startTransaction(TransactionContext("first transaction", "ui.load")) | ||
| assertSessionTraceBaggage( | ||
| firstTransaction, | ||
| scopes, | ||
| sessionTraceId.get(), | ||
| sessionSampleRand.get(), | ||
| ) | ||
| firstTransaction.finish() | ||
|
|
||
| val secondTransaction = | ||
| scopes.startTransaction(TransactionContext("second transaction", "ui.action")) | ||
| assertSessionTraceBaggage( | ||
| secondTransaction, | ||
| scopes, | ||
| sessionTraceId.get(), | ||
| sessionSampleRand.get(), | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| fun `when startTransaction with bindToScope set to false, transaction is not attached to the scope`() { | ||
| val scopes = generateScopes() | ||
|
|
@@ -4408,6 +4450,30 @@ class ScopesTest { | |
| return createScopes(options) | ||
| } | ||
|
|
||
| private fun assertSessionTraceBaggage( | ||
| transaction: ITransaction, | ||
| scopes: IScopes, | ||
| sessionTraceId: SentryId, | ||
| sessionSampleRand: Double, | ||
| ) { | ||
| assertTrue(transaction is SentryTracer) | ||
| assertEquals(sessionTraceId, transaction.root.spanContext.traceId) | ||
|
|
||
| val tracingHeaders = | ||
| TracingUtils.traceIfAllowed(scopes, "https://sentry.io/hello", emptyList(), transaction) | ||
| val baggage = | ||
| Baggage.fromHeader(tracingHeaders!!.baggageHeader!!.value, NoOpLogger.getInstance()) | ||
|
|
||
| assertEquals(sessionTraceId.toString(), baggage.traceId) | ||
| assertEquals(transaction.name, baggage.transaction) | ||
| assertEquals("true", baggage.sampled) | ||
| assertEquals(1.0, baggage.sampleRate!!, 0.0001) | ||
| assertEquals(sessionSampleRand, baggage.sampleRand!!, 0.0001) | ||
| assertEquals("key", baggage.publicKey) | ||
| assertEquals("1.0.0", baggage.release) | ||
| assertEquals("production", baggage.environment) | ||
| } | ||
|
|
||
| private fun getEnabledScopes( | ||
| optionsConfiguration: Sentry.OptionsConfiguration<SentryOptions>? = null | ||
| ): Triple<Scopes, ISentryClient, ILogger> { | ||
|
|
||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Undoing this "unfreeze" change in #5429 again since we can rely on
Baggagestill being mutable in head of trace scenario when creating a transaction.