@@ -23,6 +23,7 @@ import java.util.Date
2323import kotlin.test.Test
2424import kotlin.test.assertEquals
2525import kotlin.test.assertFalse
26+ import kotlin.test.assertNotNull
2627import kotlin.test.assertTrue
2728
2829class OutboxSenderTest {
@@ -141,6 +142,63 @@ class OutboxSenderTest {
141142 whenever(fixture.scopes.options).thenReturn(fixture.options)
142143 whenever(fixture.options.transactionProfiler).thenReturn(NoOpTransactionProfiler .getInstance())
143144
145+ val transactionContext = TransactionContext (" fixture-name" , " http" )
146+ transactionContext.description = " fixture-request"
147+ transactionContext.status = SpanStatus .OK
148+ transactionContext.setTag(" fixture-tag" , " fixture-value" )
149+ transactionContext.samplingDecision = TracesSamplingDecision (true , 0.00000021 , 0.021 )
150+
151+ val sentryTracer = SentryTracer (transactionContext, fixture.scopes)
152+ val span = sentryTracer.startChild(" child" )
153+ span.finish(SpanStatus .OK )
154+ sentryTracer.finish()
155+
156+ val sentryTracerSpy = spy(sentryTracer)
157+ whenever(sentryTracerSpy.eventId).thenReturn(SentryId (" 3367f5196c494acaae85bbbd535379ac" ))
158+
159+ val expected = SentryTransaction (sentryTracerSpy)
160+ whenever(fixture.serializer.deserialize(any(), eq(SentryTransaction ::class .java))).thenReturn(expected)
161+
162+ val sut = fixture.getSut()
163+ val path = getTempEnvelope(fileName = " envelope-transaction-with-sample-rand.txt" )
164+ assertTrue(File (path).exists())
165+
166+ val hints = HintUtils .createWithTypeCheckHint(mock<Retryable >())
167+ sut.processEnvelopeFile(path, hints)
168+
169+ verify(fixture.scopes).captureTransaction(
170+ check {
171+ assertEquals(expected, it)
172+ assertTrue(it.isSampled)
173+ assertEquals(0.00000021 , it.samplingDecision?.sampleRate)
174+ assertEquals(0.021 , it.samplingDecision?.sampleRand)
175+ assertTrue(it.samplingDecision!! .sampled)
176+ },
177+ check {
178+ assertEquals(" b156a475de54423d9c1571df97ec7eb6" , it.traceId.toString())
179+ assertEquals(" key" , it.publicKey)
180+ assertEquals(" 0.00000021" , it.sampleRate)
181+ assertEquals(" 1.0-beta.1" , it.release)
182+ assertEquals(" prod" , it.environment)
183+ assertEquals(" usr1" , it.userId)
184+ assertEquals(" tx1" , it.transaction)
185+ },
186+ any()
187+ )
188+ assertFalse(File (path).exists())
189+
190+ // Additionally make sure we have no errors logged
191+ verify(fixture.logger, never()).log(eq(SentryLevel .ERROR ), any(), any<Any >())
192+ verify(fixture.logger, never()).log(eq(SentryLevel .ERROR ), any<String >(), any())
193+ }
194+
195+ @Test
196+ fun `backfills sampleRand` () {
197+ fixture.envelopeReader = EnvelopeReader (JsonSerializer (fixture.options))
198+ whenever(fixture.options.maxSpans).thenReturn(1000 )
199+ whenever(fixture.scopes.options).thenReturn(fixture.options)
200+ whenever(fixture.options.transactionProfiler).thenReturn(NoOpTransactionProfiler .getInstance())
201+
144202 val transactionContext = TransactionContext (" fixture-name" , " http" )
145203 transactionContext.description = " fixture-request"
146204 transactionContext.status = SpanStatus .OK
@@ -170,6 +228,7 @@ class OutboxSenderTest {
170228 assertEquals(expected, it)
171229 assertTrue(it.isSampled)
172230 assertEquals(0.00000021 , it.samplingDecision?.sampleRate)
231+ assertNotNull(it.samplingDecision?.sampleRand)
173232 assertTrue(it.samplingDecision!! .sampled)
174233 },
175234 check {
0 commit comments