@@ -150,7 +150,7 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
150
150
*/
151
151
public captureEvent ( event : Event , hint ?: EventHint , scope ?: Scope ) : string | undefined {
152
152
// ensure we haven't captured this very object before
153
- if ( hint ? .originalException && checkOrSetAlreadyCaught ( hint . originalException ) ) {
153
+ if ( hint && hint . originalException && checkOrSetAlreadyCaught ( hint . originalException ) ) {
154
154
logger . log ( ALREADY_SEEN_ERROR ) ;
155
155
return ;
156
156
}
@@ -523,6 +523,15 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
523
523
const { beforeSend, sampleRate } = this . getOptions ( ) ;
524
524
const transport = this . getTransport ( ) ;
525
525
526
+ type RecordLostEvent = NonNullable < Transport [ 'recordLostEvent' ] > ;
527
+ type RecordLostEventParams = Parameters < RecordLostEvent > ;
528
+
529
+ function recordLostEvent ( outcome : RecordLostEventParams [ 0 ] , category : RecordLostEventParams [ 1 ] ) : void {
530
+ if ( transport . recordLostEvent ) {
531
+ transport . recordLostEvent ( outcome , category ) ;
532
+ }
533
+ }
534
+
526
535
if ( ! this . _isEnabled ( ) ) {
527
536
return SyncPromise . reject ( new SentryError ( 'SDK not enabled, will not capture event.' ) ) ;
528
537
}
@@ -532,7 +541,7 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
532
541
// 0.0 === 0% events are sent
533
542
// Sampling for transaction happens somewhere else
534
543
if ( ! isTransaction && typeof sampleRate === 'number' && Math . random ( ) > sampleRate ) {
535
- transport . recordLostEvent ?. ( Outcome . SampleRate , 'event' ) ;
544
+ recordLostEvent ( Outcome . SampleRate , 'event' ) ;
536
545
return SyncPromise . reject (
537
546
new SentryError (
538
547
`Discarding event because it's not included in the random sample (sampling rate = ${ sampleRate } )` ,
@@ -543,7 +552,7 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
543
552
return this . _prepareEvent ( event , scope , hint )
544
553
. then ( prepared => {
545
554
if ( prepared === null ) {
546
- transport . recordLostEvent ?. ( Outcome . EventProcessor , event . type || 'event' ) ;
555
+ recordLostEvent ( Outcome . EventProcessor , event . type || 'event' ) ;
547
556
throw new SentryError ( 'An event processor returned null, will not send event.' ) ;
548
557
}
549
558
@@ -557,7 +566,7 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
557
566
} )
558
567
. then ( processedEvent => {
559
568
if ( processedEvent === null ) {
560
- transport . recordLostEvent ?. ( Outcome . BeforeSend , event . type || 'event' ) ;
569
+ recordLostEvent ( Outcome . BeforeSend , event . type || 'event' ) ;
561
570
throw new SentryError ( '`beforeSend` returned `null`, will not send event.' ) ;
562
571
}
563
572
0 commit comments