Skip to content

Commit c25645d

Browse files
romtsnclaude
andcommitted
test(core): Verify replayId is force-set on frozen baggage
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent f7d5b1c commit c25645d

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

sentry/src/test/java/io/sentry/SentryClientTest.kt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3285,6 +3285,40 @@ class SentryClientTest {
32853285
assertTrue(terminated == true)
32863286
}
32873287

3288+
@Test
3289+
fun `sets replayId on frozen transaction baggage after captureReplay for error events`() {
3290+
val replayId = SentryId()
3291+
fixture.sentryOptions.setReplayController(
3292+
object : ReplayController by NoOpReplayController.getInstance() {
3293+
override fun captureReplay(isTerminating: Boolean?) {}
3294+
}
3295+
)
3296+
val sut = fixture.getSut()
3297+
3298+
val baggage = Baggage(fixture.sentryOptions.logger)
3299+
baggage.traceId = SentryId().toString()
3300+
baggage.freeze()
3301+
3302+
val spanContext = SpanContext("op.load")
3303+
spanContext.baggage = baggage
3304+
val transaction = mock<ITransaction>()
3305+
whenever(transaction.spanContext).thenReturn(spanContext)
3306+
whenever(transaction.traceContext()).thenReturn(baggage.toTraceContext())
3307+
3308+
val scope = mock<IScope>()
3309+
whenever(scope.transaction).thenReturn(transaction)
3310+
whenever(scope.span).thenReturn(transaction)
3311+
whenever(scope.replayId).thenReturn(replayId)
3312+
whenever(scope.breadcrumbs).thenReturn(LinkedList<Breadcrumb>())
3313+
whenever(scope.extras).thenReturn(emptyMap())
3314+
whenever(scope.contexts).thenReturn(Contexts())
3315+
whenever(scope.propagationContext).thenReturn(PropagationContext())
3316+
3317+
sut.captureEvent(SentryEvent().apply { exceptions = listOf(SentryException()) }, scope)
3318+
3319+
assertEquals(replayId.toString(), baggage.getReplayId())
3320+
}
3321+
32883322
@Test
32893323
fun `cleans up replay folder for Backfillable replay events`() {
32903324
val dir = File(tmpDir.newFolder().absolutePath)

0 commit comments

Comments
 (0)