@@ -11,13 +11,14 @@ 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' ;
1718import type { DataCategory } from './types-hoist/datacategory' ;
1819import type { DsnComponents } from './types-hoist/dsn' ;
1920import type { DynamicSamplingContext , Envelope } from './types-hoist/envelope' ;
20- import type { ErrorEvent , Event , EventHint , TransactionEvent } from './types-hoist/event' ;
21+ import type { ErrorEvent , Event , EventHint , EventType , TransactionEvent } from './types-hoist/event' ;
2122import type { EventProcessor } from './types-hoist/eventprocessor' ;
2223import type { FeedbackEvent } from './types-hoist/feedback' ;
2324import type { Integration } from './types-hoist/integration' ;
@@ -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' ;
@@ -201,6 +203,8 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
201203 // eslint-disable-next-line @typescript-eslint/ban-types
202204 private _hooks : Record < string , Set < Function > > ;
203205
206+ private _promiseBuffer : PromiseBuffer < unknown > ;
207+
204208 /**
205209 * Initializes this client instance.
206210 *
@@ -213,6 +217,7 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
213217 this . _outcomes = { } ;
214218 this . _hooks = { } ;
215219 this . _eventProcessors = [ ] ;
220+ this . _promiseBuffer = makePromiseBuffer ( options . transportOptions ?. bufferSize ?? DEFAULT_TRANSPORT_BUFFER_SIZE ) ;
216221
217222 if ( options . dsn ) {
218223 this . _dsn = makeDsn ( options . dsn ) ;
@@ -275,9 +280,11 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
275280 } ;
276281
277282 this . _process (
278- this . eventFromException ( exception , hintWithEventId ) . then ( event =>
279- this . _captureEvent ( event , hintWithEventId , scope ) ,
280- ) ,
283+ ( ) =>
284+ this . eventFromException ( exception , hintWithEventId )
285+ . then ( event => this . _captureEvent ( event , hintWithEventId , scope ) )
286+ . then ( res => res ) ,
287+ 'error' ,
281288 ) ;
282289
283290 return hintWithEventId . event_id ;
@@ -300,12 +307,15 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
300307 } ;
301308
302309 const eventMessage = isParameterizedString ( message ) ? message : String ( message ) ;
303-
304- const promisedEvent = isPrimitive ( message )
310+ const isMessage = isPrimitive ( message ) ;
311+ const promisedEvent = isMessage
305312 ? this . eventFromMessage ( eventMessage , level , hintWithEventId )
306313 : this . eventFromException ( message , hintWithEventId ) ;
307314
308- this . _process ( promisedEvent . then ( event => this . _captureEvent ( event , hintWithEventId , currentScope ) ) ) ;
315+ this . _process (
316+ ( ) => promisedEvent . then ( event => this . _captureEvent ( event , hintWithEventId , currentScope ) ) ,
317+ isMessage ? 'unknown' : 'error' ,
318+ ) ;
309319
310320 return hintWithEventId . event_id ;
311321 }
@@ -332,9 +342,11 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
332342 const sdkProcessingMetadata = event . sdkProcessingMetadata || { } ;
333343 const capturedSpanScope : Scope | undefined = sdkProcessingMetadata . capturedSpanScope ;
334344 const capturedSpanIsolationScope : Scope | undefined = sdkProcessingMetadata . capturedSpanIsolationScope ;
345+ const dataCategory = getDataCategoryByType ( event . type ) ;
335346
336347 this . _process (
337- this . _captureEvent ( event , hintWithEventId , capturedSpanScope || currentScope , capturedSpanIsolationScope ) ,
348+ ( ) => this . _captureEvent ( event , hintWithEventId , capturedSpanScope || currentScope , capturedSpanIsolationScope ) ,
349+ dataCategory ,
338350 ) ;
339351
340352 return hintWithEventId . event_id ;
@@ -1252,7 +1264,7 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
12521264 ) ;
12531265 }
12541266
1255- const dataCategory = ( eventType === 'replay_event' ? 'replay' : eventType ) satisfies DataCategory ;
1267+ const dataCategory = getDataCategoryByType ( event . type ) ;
12561268
12571269 return this . _prepareEvent ( event , hint , currentScope , isolationScope )
12581270 . then ( prepared => {
@@ -1335,15 +1347,21 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
13351347 /**
13361348 * Occupies the client with processing and event
13371349 */
1338- protected _process < T > ( promise : PromiseLike < T > ) : void {
1350+ protected _process < T > ( taskProducer : ( ) => PromiseLike < T > , dataCategory : DataCategory ) : void {
13391351 this . _numProcessing ++ ;
1340- void promise . then (
1352+
1353+ void this . _promiseBuffer . add ( taskProducer ) . then (
13411354 value => {
13421355 this . _numProcessing -- ;
13431356 return value ;
13441357 } ,
13451358 reason => {
13461359 this . _numProcessing -- ;
1360+
1361+ if ( reason === SENTRY_BUFFER_FULL_ERROR ) {
1362+ this . recordDroppedEvent ( 'queue_overflow' , dataCategory ) ;
1363+ }
1364+
13471365 return reason ;
13481366 } ,
13491367 ) ;
@@ -1408,6 +1426,10 @@ export abstract class Client<O extends ClientOptions = ClientOptions> {
14081426 ) : PromiseLike < Event > ;
14091427}
14101428
1429+ function getDataCategoryByType ( type : EventType | 'replay_event' | undefined ) : DataCategory {
1430+ return type === 'replay_event' ? 'replay' : type || 'error' ;
1431+ }
1432+
14111433/**
14121434 * Verifies that return value of configured `beforeSend` or `beforeSendTransaction` is of expected type, and returns the value if so.
14131435 */
0 commit comments