1- import { addGlobalEventProcessor , getCurrentHub } from '@sentry/core' ;
2- import type { Event , EventHint , Exception , ExtendedError , Integration , StackParser } from '@sentry/types' ;
3- import { isInstanceOf } from '@sentry/utils' ;
1+ import type { Event , EventHint , EventProcessor , Hub , Integration } from '@sentry/types' ;
2+ import { applyAggregateErrorsToEvent } from '@sentry/utils' ;
43
54import { exceptionFromError } from '../eventbuilder' ;
65import { ContextLines } from './contextlines' ;
@@ -41,15 +40,25 @@ export class LinkedErrors implements Integration {
4140 /**
4241 * @inheritDoc
4342 */
44- public setupOnce ( ) : void {
45- addGlobalEventProcessor ( async ( event : Event , hint : EventHint ) => {
43+ public setupOnce ( addGlobalEventProcessor : ( callback : EventProcessor ) => void , getCurrentHub : ( ) => Hub ) : void {
44+ addGlobalEventProcessor ( async ( event : Event , hint ? : EventHint ) => {
4645 const hub = getCurrentHub ( ) ;
47- const self = hub . getIntegration ( LinkedErrors ) ;
4846 const client = hub . getClient ( ) ;
49- if ( client && self && self . _handler && typeof self . _handler === 'function' ) {
50- self . _handler ( client . getOptions ( ) . stackParser , event , hint ) ;
47+ const self = hub . getIntegration ( LinkedErrors ) ;
48+
49+ if ( ! client || ! self ) {
50+ return event ;
5151 }
5252
53+ applyAggregateErrorsToEvent (
54+ exceptionFromError ,
55+ client . getOptions ( ) . stackParser ,
56+ self . _key ,
57+ self . _limit ,
58+ event ,
59+ hint ,
60+ ) ;
61+
5362 // If the ContextLines integration is enabled, we add source code context to linked errors
5463 // because we can't guarantee the order that integrations are run.
5564 const contextLines = getCurrentHub ( ) . getIntegration ( ContextLines ) ;
@@ -60,35 +69,4 @@ export class LinkedErrors implements Integration {
6069 return event ;
6170 } ) ;
6271 }
63-
64- /**
65- * @inheritDoc
66- */
67- private _handler ( stackParser : StackParser , event : Event , hint : EventHint ) : Event {
68- if ( ! event . exception || ! event . exception . values || ! hint || ! isInstanceOf ( hint . originalException , Error ) ) {
69- return event ;
70- }
71-
72- const linkedErrors = this . _walkErrorTree ( stackParser , hint . originalException as ExtendedError , this . _key ) ;
73- event . exception . values = [ ...linkedErrors , ...event . exception . values ] ;
74- return event ;
75- }
76-
77- /**
78- * @inheritDoc
79- */
80- private _walkErrorTree (
81- stackParser : StackParser ,
82- error : ExtendedError ,
83- key : string ,
84- stack : Exception [ ] = [ ] ,
85- ) : Exception [ ] {
86- if ( ! isInstanceOf ( error [ key ] , Error ) || stack . length + 1 >= this . _limit ) {
87- return stack ;
88- }
89-
90- const exception = exceptionFromError ( stackParser , error [ key ] ) ;
91-
92- return this . _walkErrorTree ( stackParser , error [ key ] , key , [ exception , ...stack ] ) ;
93- }
9472}
0 commit comments