@@ -11,6 +11,7 @@ import {
11
11
import {
12
12
dateTimestampInSeconds ,
13
13
getEventDescription ,
14
+ isPlainObject ,
14
15
isPrimitive ,
15
16
logger ,
16
17
normalize ,
@@ -248,44 +249,6 @@ export abstract class BaseClient<O extends Options> implements ClientLike<O> {
248
249
this . _sendRequest ( sessionToTransportRequest ( session ) ) ;
249
250
}
250
251
251
- /**
252
- * Adds common information to events.
253
- *
254
- * The information includes release and environment from `options`,
255
- * breadcrumbs and context (extra, tags and user) from the scope.
256
- *
257
- * Information that is already present in the event is never overwritten. For
258
- * nested objects, such as the context, keys are merged.
259
- *
260
- * @param event The original event.
261
- * @param hint May contain additional information about the original exception.
262
- * @returns A new event with more information.
263
- */
264
- protected _prepareEvent ( event : SentryEvent , captureContext : CaptureContext ) : SentryEvent | null {
265
- const { normalizeDepth = 3 } = this . options ;
266
- const prepared : SentryEvent = {
267
- ...event ,
268
- event_id : event . event_id ?? uuid4 ( ) ,
269
- timestamp : event . timestamp ?? dateTimestampInSeconds ( ) ,
270
- } ;
271
-
272
- this . _applyClientOptions ( prepared ) ;
273
- this . _applyIntegrationsMetadata ( prepared ) ;
274
-
275
- const scope =
276
- captureContext . scope instanceof Scope
277
- ? captureContext . scope
278
- : this . getScope ( )
279
- . clone ( )
280
- . update ( captureContext . scope ) ;
281
-
282
- const processedEvent = scope . applyToEvent ( prepared , captureContext . hint ) ;
283
- if ( typeof normalizeDepth === 'number' && normalizeDepth > 0 ) {
284
- return this . _normalizeEvent ( processedEvent , normalizeDepth ) ;
285
- }
286
- return processedEvent ;
287
- }
288
-
289
252
/**
290
253
* Applies `normalize` function on necessary `Event` attributes to make them safe for serialization.
291
254
* Normalized keys:
@@ -434,6 +397,7 @@ export abstract class BaseClient<O extends Options> implements ClientLike<O> {
434
397
* @param scope A scope containing event metadata.
435
398
* @returns A Promise that resolves with the event or rejects in case event was/will not be send.
436
399
*/
400
+ // eslint-disable-next-line complexity
437
401
protected _processEvent ( event : SentryEvent , captureContext : CaptureContext ) : SentryEvent | null {
438
402
if ( this . options . enabled === false ) {
439
403
logger . error ( 'SDK not enabled, will not send event.' ) ;
@@ -452,24 +416,57 @@ export abstract class BaseClient<O extends Options> implements ClientLike<O> {
452
416
}
453
417
454
418
try {
455
- let processedEvent = this . _prepareEvent ( event , captureContext ) ;
419
+ let processedEvent : SentryEvent | null = {
420
+ ...event ,
421
+ event_id : event . event_id ?? uuid4 ( ) ,
422
+ timestamp : event . timestamp ?? dateTimestampInSeconds ( ) ,
423
+ } ;
424
+
425
+ this . _applyClientOptions ( processedEvent ) ;
426
+ this . _applyIntegrationsMetadata ( processedEvent ) ;
427
+
428
+ const scope =
429
+ captureContext . scope instanceof Scope
430
+ ? captureContext . scope
431
+ : this . getScope ( )
432
+ . clone ( )
433
+ . update ( captureContext . scope ) ;
434
+
435
+ processedEvent = scope . applyToEvent ( processedEvent , captureContext . hint ) ;
436
+ if ( processedEvent === null ) {
437
+ logger . error ( 'A scope event processor returned null, will not send event.' ) ;
438
+ return null ;
439
+ }
440
+
441
+ for ( const processor of this . _eventProcessors ) {
442
+ if ( typeof processor === 'function' ) {
443
+ const nextEvent = processor ( processedEvent , captureContext . hint ) ;
444
+ if ( nextEvent === null ) {
445
+ logger . error ( 'A client event processor returned null, will not send event.' ) ;
446
+ return null ;
447
+ }
448
+ processedEvent = nextEvent ;
449
+ }
450
+ }
456
451
457
452
if ( processedEvent === null ) {
458
- logger . error ( 'An event processor returned null, will not send event.' ) ;
453
+ logger . error ( 'A scope event processor returned null, will not send event.' ) ;
459
454
return null ;
460
455
}
461
456
462
- const isInternalException =
463
- captureContext ?. hint &&
464
- captureContext ?. hint ?. data &&
465
- ( captureContext ?. hint ?. data as { __sentry__ : boolean } ) . __sentry__ === true ;
457
+ const normalizeDepth = this . options . normalizeDepth ?? 3 ;
458
+ if ( typeof normalizeDepth === 'number' && normalizeDepth > 0 ) {
459
+ processedEvent = this . _normalizeEvent ( processedEvent , normalizeDepth ) ;
460
+ }
461
+
462
+ const isInternalException = captureContext ?. hint ?. data ?. __sentry__ === true ;
466
463
if ( isInternalException || isTransaction || ! this . options . beforeSend ) {
467
464
return processedEvent ;
468
465
}
469
466
470
- processedEvent = this . options . beforeSend ( processedEvent , captureContext ?. hint ) ;
467
+ processedEvent = this . options . beforeSend ( processedEvent as SentryEvent , captureContext ?. hint ) ;
471
468
472
- if ( typeof processedEvent === 'undefined' ) {
469
+ if ( ! ( isPlainObject ( processedEvent ) || processedEvent === null ) ) {
473
470
logger . error ( '`beforeSend` method has to return `null` or a valid event.' ) ;
474
471
return null ;
475
472
}
0 commit comments