@@ -11,6 +11,7 @@ import { _INTERNAL_flushMetricsBuffer } from './metrics/internal';
1111import type { Scope } from './scope' ;
1212import { updateSession } from './session' ;
1313import { getDynamicSamplingContextFromScope } from './tracing/dynamicSamplingContext' ;
14+ import { DEFAULT_TRANSPORT_BUFFER_SIZE } from './transports/base' ;
1415import type { Breadcrumb , BreadcrumbHint , FetchBreadcrumbHint , XhrBreadcrumbHint } from './types-hoist/breadcrumb' ;
1516import type { CheckIn , MonitorConfig } from './types-hoist/checkin' ;
1617import type { EventDropReason , Outcome } from './types-hoist/clientreport' ;
@@ -43,6 +44,7 @@ import { merge } from './utils/merge';
4344import { checkOrSetAlreadyCaught , uuid4 } from './utils/misc' ;
4445import { parseSampleRate } from './utils/parseSampleRate' ;
4546import { prepareEvent } from './utils/prepareEvent' ;
47+ import { type PromiseBuffer , makePromiseBuffer , SENTRY_BUFFER_FULL_ERROR } from './utils/promisebuffer' ;
4648import { reparentChildSpans , shouldIgnoreSpan } from './utils/should-ignore-span' ;
4749import { showSpanDropWarning } from './utils/spanUtils' ;
4850import { rejectedSyncPromise } from './utils/syncpromise' ;
@@ -194,6 +196,8 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
194196 // eslint-disable-next-line @typescript-eslint/ban-types
195197 private _hooks : Record < string , Set < Function > > ;
196198
199+ private _promiseBuffer : PromiseBuffer < unknown > ;
200+
197201 /**
198202 * Initializes this client instance.
199203 *
@@ -206,6 +210,7 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
206210 this . _outcomes = { } ;
207211 this . _hooks = { } ;
208212 this . _eventProcessors = [ ] ;
213+ this . _promiseBuffer = makePromiseBuffer ( options . transportOptions ?. bufferSize ?? DEFAULT_TRANSPORT_BUFFER_SIZE ) ;
209214
210215 if ( options . dsn ) {
211216 this . _dsn = makeDsn ( options . dsn ) ;
@@ -268,9 +273,11 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
268273 } ;
269274
270275 this . _process (
271- this . eventFromException ( exception , hintWithEventId ) . then ( event =>
272- this . _captureEvent ( event , hintWithEventId , scope ) ,
273- ) ,
276+ ( ) =>
277+ this . eventFromException ( exception , hintWithEventId )
278+ . then ( event => this . _captureEvent ( event , hintWithEventId , scope ) )
279+ . then ( res => res ) ,
280+ 'error' ,
274281 ) ;
275282
276283 return hintWithEventId . event_id ;
@@ -293,12 +300,15 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
293300 } ;
294301
295302 const eventMessage = isParameterizedString ( message ) ? message : String ( message ) ;
296-
297- const promisedEvent = isPrimitive ( message )
303+ const isMessage = isPrimitive ( message ) ;
304+ const promisedEvent = isMessage
298305 ? this . eventFromMessage ( eventMessage , level , hintWithEventId )
299306 : this . eventFromException ( message , hintWithEventId ) ;
300307
301- this . _process ( promisedEvent . then ( event => this . _captureEvent ( event , hintWithEventId , currentScope ) ) ) ;
308+ this . _process (
309+ ( ) => promisedEvent . then ( event => this . _captureEvent ( event , hintWithEventId , currentScope ) ) ,
310+ isMessage ? 'unknown' : 'error' ,
311+ ) ;
302312
303313 return hintWithEventId . event_id ;
304314 }
@@ -325,9 +335,11 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
325335 const sdkProcessingMetadata = event . sdkProcessingMetadata || { } ;
326336 const capturedSpanScope : Scope | undefined = sdkProcessingMetadata . capturedSpanScope ;
327337 const capturedSpanIsolationScope : Scope | undefined = sdkProcessingMetadata . capturedSpanIsolationScope ;
338+ const dataCategory = event . type === 'replay_event' ? 'replay' : ( event . type ?? 'unknown' ) ;
328339
329340 this . _process (
330- this . _captureEvent ( event , hintWithEventId , capturedSpanScope || currentScope , capturedSpanIsolationScope ) ,
341+ ( ) => this . _captureEvent ( event , hintWithEventId , capturedSpanScope || currentScope , capturedSpanIsolationScope ) ,
342+ dataCategory ,
331343 ) ;
332344
333345 return hintWithEventId . event_id ;
@@ -1312,15 +1324,21 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
13121324 /**
13131325 * Occupies the client with processing and event
13141326 */
1315- protected _process < T > ( promise : PromiseLike < T > ) : void {
1327+ protected _process < T > ( taskProducer : ( ) => PromiseLike < T > , dataCategory : DataCategory ) : void {
13161328 this . _numProcessing ++ ;
1317- void promise . then (
1329+
1330+ void this . _promiseBuffer . add ( taskProducer ) . then (
13181331 value => {
13191332 this . _numProcessing -- ;
13201333 return value ;
13211334 } ,
13221335 reason => {
13231336 this . _numProcessing -- ;
1337+
1338+ if ( reason === SENTRY_BUFFER_FULL_ERROR ) {
1339+ this . recordDroppedEvent ( 'queue_overflow' , dataCategory ) ;
1340+ }
1341+
13241342 return reason ;
13251343 } ,
13261344 ) ;
0 commit comments