@@ -89,7 +89,8 @@ class SentryClientTest {
8989 init {
9090 whenever(factory.create(any(), any())).thenReturn(transport)
9191 whenever(hub.options).thenReturn(sentryOptions)
92- sentryTracer = SentryTracer (TransactionContext (" a-transaction" , " op" ), hub)
92+ sentryTracer = SentryTracer (TransactionContext (" a-transaction" , " op" , TracesSamplingDecision (true )), hub)
93+ sentryTracer.startChild(" a-span" , " span 1" ).finish()
9394 }
9495
9596 var attachment = Attachment (" hello" .toByteArray(), " hello.txt" , " text/plain" , true )
@@ -807,7 +808,10 @@ class SentryClientTest {
807808
808809 assertClientReport(
809810 fixture.sentryOptions.clientReportRecorder,
810- listOf (DiscardedEvent (DiscardReason .EVENT_PROCESSOR .reason, DataCategory .Transaction .category, 1 ))
811+ listOf (
812+ DiscardedEvent (DiscardReason .EVENT_PROCESSOR .reason, DataCategory .Transaction .category, 1 ),
813+ DiscardedEvent (DiscardReason .EVENT_PROCESSOR .reason, DataCategory .Span .category, 2 )
814+ )
811815 )
812816 }
813817
@@ -893,7 +897,10 @@ class SentryClientTest {
893897
894898 assertClientReport(
895899 fixture.sentryOptions.clientReportRecorder,
896- listOf (DiscardedEvent (DiscardReason .BEFORE_SEND .reason, DataCategory .Transaction .category, 1 ))
900+ listOf (
901+ DiscardedEvent (DiscardReason .BEFORE_SEND .reason, DataCategory .Transaction .category, 1 ),
902+ DiscardedEvent (DiscardReason .BEFORE_SEND .reason, DataCategory .Span .category, 2 )
903+ )
897904 )
898905 }
899906
@@ -909,7 +916,36 @@ class SentryClientTest {
909916
910917 assertClientReport(
911918 fixture.sentryOptions.clientReportRecorder,
912- listOf (DiscardedEvent (DiscardReason .EVENT_PROCESSOR .reason, DataCategory .Transaction .category, 1 ))
919+ listOf (
920+ DiscardedEvent (DiscardReason .EVENT_PROCESSOR .reason, DataCategory .Transaction .category, 1 ),
921+ DiscardedEvent (DiscardReason .EVENT_PROCESSOR .reason, DataCategory .Span .category, 2 )
922+ )
923+ )
924+ }
925+
926+ @Test
927+ fun `span dropped by event processor is recorded` () {
928+ fixture.sentryTracer.startChild(" dropped span" , " span1" ).finish()
929+ fixture.sentryTracer.startChild(" dropped span" , " span2" ).finish()
930+ val transaction = SentryTransaction (fixture.sentryTracer)
931+ val scope = createScope()
932+ scope.addEventProcessor(object : EventProcessor {
933+ override fun process (transaction : SentryTransaction , hint : Hint ): SentryTransaction ? {
934+ // we are removing span1 and a-span from the fixture
935+ transaction.spans.removeIf { it.description != " span2" }
936+ return transaction
937+ }
938+ })
939+
940+ fixture.getSut().captureTransaction(transaction, scope, null )
941+
942+ verify(fixture.transport).send(any(), anyOrNull())
943+
944+ assertClientReport(
945+ fixture.sentryOptions.clientReportRecorder,
946+ listOf (
947+ DiscardedEvent (DiscardReason .EVENT_PROCESSOR .reason, DataCategory .Span .category, 2 )
948+ )
913949 )
914950 }
915951
@@ -969,7 +1005,10 @@ class SentryClientTest {
9691005
9701006 assertClientReport(
9711007 fixture.sentryOptions.clientReportRecorder,
972- listOf (DiscardedEvent (DiscardReason .BEFORE_SEND .reason, DataCategory .Transaction .category, 1 ))
1008+ listOf (
1009+ DiscardedEvent (DiscardReason .BEFORE_SEND .reason, DataCategory .Transaction .category, 1 ),
1010+ DiscardedEvent (DiscardReason .BEFORE_SEND .reason, DataCategory .Span .category, 2 )
1011+ )
9731012 )
9741013 }
9751014
@@ -1007,7 +1046,34 @@ class SentryClientTest {
10071046
10081047 assertClientReport(
10091048 fixture.sentryOptions.clientReportRecorder,
1010- listOf (DiscardedEvent (DiscardReason .BEFORE_SEND .reason, DataCategory .Transaction .category, 1 ))
1049+ listOf (
1050+ DiscardedEvent (DiscardReason .BEFORE_SEND .reason, DataCategory .Transaction .category, 1 ),
1051+ DiscardedEvent (DiscardReason .BEFORE_SEND .reason, DataCategory .Span .category, 2 )
1052+ )
1053+ )
1054+ }
1055+
1056+ @Test
1057+ fun `when beforeSendTransaction drops a span, dropped span is recorded` () {
1058+ fixture.sentryTracer.startChild(" dropped span" , " span1" ).finish()
1059+ fixture.sentryTracer.startChild(" dropped span" , " span2" ).finish()
1060+ fixture.sentryOptions.setBeforeSendTransaction { t: SentryTransaction , _: Any? ->
1061+ t.apply {
1062+ // we are removing span1 and a-span from the fixture
1063+ spans.removeIf { it.description != " span2" }
1064+ }
1065+ }
1066+
1067+ val transaction = SentryTransaction (fixture.sentryTracer)
1068+ fixture.getSut().captureTransaction(transaction, fixture.sentryTracer.traceContext())
1069+
1070+ verify(fixture.transport).send(any(), anyOrNull())
1071+
1072+ assertClientReport(
1073+ fixture.sentryOptions.clientReportRecorder,
1074+ listOf (
1075+ DiscardedEvent (DiscardReason .BEFORE_SEND .reason, DataCategory .Span .category, 2 )
1076+ )
10111077 )
10121078 }
10131079
0 commit comments