@@ -613,13 +613,17 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
613
613
* @returns A SyncPromise that resolves with the event or rejects in case event was/will not be send.
614
614
*/
615
615
protected _processEvent ( event : Event , hint : EventHint , scope ?: Scope ) : PromiseLike < Event > {
616
- const { beforeSend, sampleRate } = this . getOptions ( ) ;
616
+ const options = this . getOptions ( ) ;
617
+ const { sampleRate } = options ;
617
618
618
619
if ( ! this . _isEnabled ( ) ) {
619
620
return rejectedSyncPromise ( new SentryError ( 'SDK not enabled, will not capture event.' , 'log' ) ) ;
620
621
}
621
622
622
623
const isTransaction = event . type === 'transaction' ;
624
+ const beforeSendProcessorName = isTransaction ? 'beforeSendTransaction' : 'beforeSend' ;
625
+ const beforeSendProcessor = options [ beforeSendProcessorName ] ;
626
+
623
627
// 1.0 === 100% events are sent
624
628
// 0.0 === 0% events are sent
625
629
// Sampling for transaction happens somewhere else
@@ -641,17 +645,17 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
641
645
}
642
646
643
647
const isInternalException = hint . data && ( hint . data as { __sentry__ : boolean } ) . __sentry__ === true ;
644
- if ( isInternalException || isTransaction || ! beforeSend ) {
648
+ if ( isInternalException || ! beforeSendProcessor ) {
645
649
return prepared ;
646
650
}
647
651
648
- const beforeSendResult = beforeSend ( prepared , hint ) ;
649
- return _ensureBeforeSendRv ( beforeSendResult ) ;
652
+ const beforeSendResult = beforeSendProcessor ( prepared , hint ) ;
653
+ return _ensureBeforeSendRv ( beforeSendResult , beforeSendProcessorName ) ;
650
654
} )
651
655
. then ( processedEvent => {
652
656
if ( processedEvent === null ) {
653
657
this . recordDroppedEvent ( 'before_send' , event . type || 'error' ) ;
654
- throw new SentryError ( '`beforeSend` returned `null`, will not send event.' , 'log' ) ;
658
+ throw new SentryError ( `\` ${ beforeSendProcessorName } \` returned \ `null\ `, will not send event.` , 'log' ) ;
655
659
}
656
660
657
661
const session = scope && scope . getSession ( ) ;
@@ -764,10 +768,13 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
764
768
}
765
769
766
770
/**
767
- * Verifies that return value of configured `beforeSend` is of expected type.
771
+ * Verifies that return value of configured `beforeSend` or `beforeSendTransaction` is of expected type.
768
772
*/
769
- function _ensureBeforeSendRv ( rv : PromiseLike < Event | null > | Event | null ) : PromiseLike < Event | null > | Event | null {
770
- const nullErr = '`beforeSend` method has to return `null` or a valid event.' ;
773
+ function _ensureBeforeSendRv (
774
+ rv : PromiseLike < Event | null > | Event | null ,
775
+ beforeSendProcessorName : string ,
776
+ ) : PromiseLike < Event | null > | Event | null {
777
+ const nullErr = `\`${ beforeSendProcessorName } \` must return \`null\` or a valid event.` ;
771
778
if ( isThenable ( rv ) ) {
772
779
return rv . then (
773
780
event => {
@@ -777,7 +784,7 @@ function _ensureBeforeSendRv(rv: PromiseLike<Event | null> | Event | null): Prom
777
784
return event ;
778
785
} ,
779
786
e => {
780
- throw new SentryError ( `beforeSend rejected with ${ e } ` ) ;
787
+ throw new SentryError ( `${ beforeSendProcessorName } rejected with ${ e } ` ) ;
781
788
} ,
782
789
) ;
783
790
} else if ( ! ( isPlainObject ( rv ) || rv === null ) ) {
0 commit comments