@@ -150,7 +150,7 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
150150 */
151151 public captureEvent ( event : Event , hint ?: EventHint , scope ?: Scope ) : string | undefined {
152152 // ensure we haven't captured this very object before
153- if ( hint ? .originalException && checkOrSetAlreadyCaught ( hint . originalException ) ) {
153+ if ( hint && hint . originalException && checkOrSetAlreadyCaught ( hint . originalException ) ) {
154154 logger . log ( ALREADY_SEEN_ERROR ) ;
155155 return ;
156156 }
@@ -523,6 +523,15 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
523523 const { beforeSend, sampleRate } = this . getOptions ( ) ;
524524 const transport = this . getTransport ( ) ;
525525
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+
526535 if ( ! this . _isEnabled ( ) ) {
527536 return SyncPromise . reject ( new SentryError ( 'SDK not enabled, will not capture event.' ) ) ;
528537 }
@@ -532,7 +541,7 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
532541 // 0.0 === 0% events are sent
533542 // Sampling for transaction happens somewhere else
534543 if ( ! isTransaction && typeof sampleRate === 'number' && Math . random ( ) > sampleRate ) {
535- transport . recordLostEvent ?. ( Outcome . SampleRate , 'event' ) ;
544+ recordLostEvent ( Outcome . SampleRate , 'event' ) ;
536545 return SyncPromise . reject (
537546 new SentryError (
538547 `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
543552 return this . _prepareEvent ( event , scope , hint )
544553 . then ( prepared => {
545554 if ( prepared === null ) {
546- transport . recordLostEvent ?. ( Outcome . EventProcessor , event . type || 'event' ) ;
555+ recordLostEvent ( Outcome . EventProcessor , event . type || 'event' ) ;
547556 throw new SentryError ( 'An event processor returned null, will not send event.' ) ;
548557 }
549558
@@ -557,7 +566,7 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
557566 } )
558567 . then ( processedEvent => {
559568 if ( processedEvent === null ) {
560- transport . recordLostEvent ?. ( Outcome . BeforeSend , event . type || 'event' ) ;
569+ recordLostEvent ( Outcome . BeforeSend , event . type || 'event' ) ;
561570 throw new SentryError ( '`beforeSend` returned `null`, will not send event.' ) ;
562571 }
563572
0 commit comments