@@ -412,6 +412,7 @@ private SentryTransaction processTransaction(
412
412
final @ NotNull Hint hint ,
413
413
final @ NotNull List <EventProcessor > eventProcessors ) {
414
414
for (final EventProcessor processor : eventProcessors ) {
415
+ final int spanCountBeforeProcessor = transaction .getSpans ().size ();
415
416
try {
416
417
transaction = processor .process (transaction , hint );
417
418
} catch (Throwable e ) {
@@ -423,6 +424,7 @@ private SentryTransaction processTransaction(
423
424
"An exception occurred while processing transaction by processor: %s" ,
424
425
processor .getClass ().getName ());
425
426
}
427
+ final int spanCountAfterProcessor = transaction == null ? 0 : transaction .getSpans ().size ();
426
428
427
429
if (transaction == null ) {
428
430
options
@@ -434,7 +436,25 @@ private SentryTransaction processTransaction(
434
436
options
435
437
.getClientReportRecorder ()
436
438
.recordLostEvent (DiscardReason .EVENT_PROCESSOR , DataCategory .Transaction );
439
+ // If we drop a transaction, we are also dropping all its spans (+1 for the root span)
440
+ options
441
+ .getClientReportRecorder ()
442
+ .recordLostEvent (
443
+ DiscardReason .EVENT_PROCESSOR , DataCategory .Span , spanCountBeforeProcessor + 1 );
437
444
break ;
445
+ } else if (spanCountAfterProcessor < spanCountBeforeProcessor ) {
446
+ // If the callback removed some spans, we report it
447
+ final int droppedSpanCount = spanCountBeforeProcessor - spanCountAfterProcessor ;
448
+ options
449
+ .getLogger ()
450
+ .log (
451
+ SentryLevel .DEBUG ,
452
+ "%d spans were dropped by a processor: %s" ,
453
+ droppedSpanCount ,
454
+ processor .getClass ().getName ());
455
+ options
456
+ .getClientReportRecorder ()
457
+ .recordLostEvent (DiscardReason .EVENT_PROCESSOR , DataCategory .Span , droppedSpanCount );
438
458
}
439
459
}
440
460
return transaction ;
@@ -666,7 +686,9 @@ public void captureSession(final @NotNull Session session, final @Nullable Hint
666
686
return SentryId .EMPTY_ID ;
667
687
}
668
688
689
+ final int spanCountBeforeCallback = transaction .getSpans ().size ();
669
690
transaction = executeBeforeSendTransaction (transaction , hint );
691
+ final int spanCountAfterCallback = transaction == null ? 0 : transaction .getSpans ().size ();
670
692
671
693
if (transaction == null ) {
672
694
options
@@ -675,7 +697,24 @@ public void captureSession(final @NotNull Session session, final @Nullable Hint
675
697
options
676
698
.getClientReportRecorder ()
677
699
.recordLostEvent (DiscardReason .BEFORE_SEND , DataCategory .Transaction );
700
+ // If we drop a transaction, we are also dropping all its spans (+1 for the root span)
701
+ options
702
+ .getClientReportRecorder ()
703
+ .recordLostEvent (
704
+ DiscardReason .BEFORE_SEND , DataCategory .Span , spanCountBeforeCallback + 1 );
678
705
return SentryId .EMPTY_ID ;
706
+ } else if (spanCountAfterCallback < spanCountBeforeCallback ) {
707
+ // If the callback removed some spans, we report it
708
+ final int droppedSpanCount = spanCountBeforeCallback - spanCountAfterCallback ;
709
+ options
710
+ .getLogger ()
711
+ .log (
712
+ SentryLevel .DEBUG ,
713
+ "%d spans were dropped by beforeSendTransaction." ,
714
+ droppedSpanCount );
715
+ options
716
+ .getClientReportRecorder ()
717
+ .recordLostEvent (DiscardReason .BEFORE_SEND , DataCategory .Span , droppedSpanCount );
679
718
}
680
719
681
720
try {
0 commit comments