88 Event ,
99 EventDropReason ,
1010 EventHint ,
11+ EventType ,
1112 Integration ,
1213 IntegrationClass ,
1314 Outcome ,
@@ -42,6 +43,8 @@ import { IntegrationIndex, setupIntegrations } from './integration';
4243import { Scope } from './scope' ;
4344import { updateSession } from './session' ;
4445
46+ type BeforeSendProcessorMethod = 'beforeSend' | 'beforeSendTransaction' ;
47+
4548const ALREADY_SEEN_ERROR = "Not capturing exception because it's already been captured." ;
4649
4750/**
@@ -628,13 +631,20 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
628631 }
629632
630633 const isTransaction = event . type === 'transaction' ;
631- const beforeSendProcessorName = isTransaction ? 'beforeSendTransaction' : 'beforeSend' ;
632- const beforeSendProcessor = options [ beforeSendProcessorName ] ;
634+ const isError = ! event . type ;
635+
636+ const beforeSendProcessorMap : Map < EventType | undefined , BeforeSendProcessorMethod | undefined > = new Map ( [
637+ [ undefined , 'beforeSend' ] ,
638+ [ 'transaction' , 'beforeSendTransaction' ] ,
639+ ] ) ;
640+
641+ const beforeSendProcessorName = beforeSendProcessorMap . get ( event . type ) ;
642+ const beforeSendProcessor = beforeSendProcessorName ? options [ beforeSendProcessorName ] : undefined ;
633643
634644 // 1.0 === 100% events are sent
635645 // 0.0 === 0% events are sent
636646 // Sampling for transaction happens somewhere else
637- if ( ! isTransaction && typeof sampleRate === 'number' && Math . random ( ) > sampleRate ) {
647+ if ( isError && typeof sampleRate === 'number' && Math . random ( ) > sampleRate ) {
638648 this . recordDroppedEvent ( 'sample_rate' , 'error' , event ) ;
639649 return rejectedSyncPromise (
640650 new SentryError (
@@ -657,7 +667,7 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
657667 }
658668
659669 const beforeSendResult = beforeSendProcessor ( prepared , hint ) ;
660- return _validateBeforeSendResult ( beforeSendResult , beforeSendProcessorName ) ;
670+ return _validateBeforeSendResult ( beforeSendResult , beforeSendProcessorName as BeforeSendProcessorMethod ) ;
661671 } )
662672 . then ( processedEvent => {
663673 if ( processedEvent === null ) {
0 commit comments