Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sentry/src/main/java/io/sentry/Baggage.java
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ public Baggage(final @NotNull Baggage baggage) {
baggage.sampleRate,
sampleRand,
baggage.thirdPartyHeader,
baggage.mutable,
baggage.shouldFreeze,
true,
false,
baggage.logger);
}

Expand Down
5 changes: 3 additions & 2 deletions sentry/src/test/java/io/sentry/BaggageTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ class BaggageTest {
}

@Test
fun `copy with overrides preserves frozen state`() {
fun `copy with overrides creates mutable baggage`() {
val baggage =
Baggage.fromHeader(
"sentry-sample_rand=0.1,sentry-trace_id=75302ac48a024bde9a3b3734a82e36c8",
Expand All @@ -450,7 +450,8 @@ class BaggageTest {

val copy = Baggage.copyWithOverrides(baggage, SentryId("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"), 0.2)

assertFalse(copy.isMutable)
assertTrue(copy.isMutable)
assertFalse(copy.isShouldFreeze)
assertEquals("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", copy.traceId)
assertEquals(0.2, copy.sampleRand!!, 0.0001)
assertEquals("75302ac48a024bde9a3b3734a82e36c8", baggage.traceId)
Expand Down
66 changes: 66 additions & 0 deletions sentry/src/test/java/io/sentry/ScopesTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}

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()
Expand Down Expand Up @@ -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> {
Expand Down
Loading