@@ -4,6 +4,7 @@ import io.sentry.protocol.SentryId
44import io.sentry.protocol.TransactionNameSource
55import io.sentry.protocol.User
66import io.sentry.test.createTestScopes
7+ import io.sentry.test.getProperty
78import io.sentry.util.thread.IThreadChecker
89import java.time.LocalDateTime
910import java.time.ZoneOffset
@@ -1173,12 +1174,17 @@ class SentryTracerTest {
11731174 fun `when transaction is created and sampled, but not profiled, compositePerformanceCollector is started anyway` () {
11741175 val transaction = fixture.getSut(samplingDecision = TracesSamplingDecision (true ))
11751176 verify(fixture.compositePerformanceCollector).start(anyOrNull<ITransaction >())
1177+ assertEquals(
1178+ fixture.compositePerformanceCollector,
1179+ transaction.getProperty(" compositePerformanceCollector" ),
1180+ )
11761181 }
11771182
11781183 @Test
1179- fun `when transaction is created, but not sampled, compositePerformanceCollector is not started` () {
1184+ fun `when transaction is created, but not sampled, compositePerformanceCollector is not started nor set ` () {
11801185 val transaction = fixture.getSut(samplingDecision = TracesSamplingDecision (false ))
11811186 verify(fixture.compositePerformanceCollector, never()).start(anyOrNull<ITransaction >())
1187+ assertNull(transaction.getProperty(" compositePerformanceCollector" ))
11821188 }
11831189
11841190 @Test
@@ -1194,15 +1200,15 @@ class SentryTracerTest {
11941200
11951201 @Test
11961202 fun `when transaction is finished, compositePerformanceCollector is stopped` () {
1197- val transaction = fixture.getSut()
1203+ val transaction = fixture.getSut(samplingDecision = TracesSamplingDecision ( true ) )
11981204 transaction.finish()
11991205 verify(fixture.compositePerformanceCollector)
12001206 .stop(check<ITransaction > { assertEquals(transaction, it) })
12011207 }
12021208
12031209 @Test
12041210 fun `when a span is started and finished the compositePerformanceCollector gets notified` () {
1205- val transaction = fixture.getSut()
1211+ val transaction = fixture.getSut(samplingDecision = TracesSamplingDecision ( true ) )
12061212
12071213 val span = transaction.startChild(" op.span" )
12081214 span.finish()
@@ -1211,6 +1217,17 @@ class SentryTracerTest {
12111217 verify(fixture.compositePerformanceCollector).onSpanFinished(check { assertEquals(span, it) })
12121218 }
12131219
1220+ @Test
1221+ fun `when a span is started and finished the compositePerformanceCollector gets never notified if not sampled` () {
1222+ val transaction = fixture.getSut(samplingDecision = TracesSamplingDecision (false ))
1223+
1224+ val span = transaction.startChild(" op.span" )
1225+ span.finish()
1226+
1227+ verify(fixture.compositePerformanceCollector, never()).onSpanStarted(any())
1228+ verify(fixture.compositePerformanceCollector, never()).onSpanFinished(any())
1229+ }
1230+
12141231 @Test
12151232 fun `changing transaction name without source sets source to custom` () {
12161233 val transaction = fixture.getSut()
@@ -1399,6 +1416,7 @@ class SentryTracerTest {
13991416 }
14001417 val transaction =
14011418 fixture.getSut(
1419+ samplingDecision = TracesSamplingDecision (true ),
14021420 optionsConfiguration = { it.profilesSampleRate = 1.0 },
14031421 performanceCollector = mockPerformanceCollector,
14041422 )
0 commit comments