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' ;
4
3
5
4
import { exceptionFromError } from '../eventbuilder' ;
6
5
import { ContextLines } from './contextlines' ;
@@ -41,15 +40,25 @@ export class LinkedErrors implements Integration {
41
40
/**
42
41
* @inheritDoc
43
42
*/
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 ) => {
46
45
const hub = getCurrentHub ( ) ;
47
- const self = hub . getIntegration ( LinkedErrors ) ;
48
46
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 ;
51
51
}
52
52
53
+ applyAggregateErrorsToEvent (
54
+ exceptionFromError ,
55
+ client . getOptions ( ) . stackParser ,
56
+ self . _key ,
57
+ self . _limit ,
58
+ event ,
59
+ hint ,
60
+ ) ;
61
+
53
62
// If the ContextLines integration is enabled, we add source code context to linked errors
54
63
// because we can't guarantee the order that integrations are run.
55
64
const contextLines = getCurrentHub ( ) . getIntegration ( ContextLines ) ;
@@ -60,35 +69,4 @@ export class LinkedErrors implements Integration {
60
69
return event ;
61
70
} ) ;
62
71
}
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
- }
94
72
}
0 commit comments