@@ -62,24 +62,6 @@ function hashFrames(frames: StackFrame[] | undefined): string | undefined {
62
62
return frames . reduce ( ( acc , frame ) => `${ acc } ,${ frame . function } ,${ frame . lineno } ,${ frame . colno } ` , '' ) ;
63
63
}
64
64
65
- type HashFromStackFn = ( stack : string | undefined ) => string | undefined ;
66
-
67
- /**
68
- * Creates a function used to hash stack strings
69
- *
70
- * We use the stack parser to create a unique hash from the exception stack trace
71
- * This is used to lookup vars when the exception passes through the event processor
72
- */
73
- function createHashFn ( stackParser : StackParser | undefined ) : HashFromStackFn {
74
- return ( stack : string | undefined ) => {
75
- if ( stackParser === undefined || stack === undefined ) {
76
- return undefined ;
77
- }
78
-
79
- return hashFrames ( stackParser ( stack , 1 ) ) ;
80
- } ;
81
- }
82
-
83
65
interface FrameVariables {
84
66
function : string ;
85
67
vars ?: Record < string , unknown > ;
@@ -95,6 +77,7 @@ export class LocalVariables implements Integration {
95
77
96
78
private readonly _session : AsyncSession = new AsyncSession ( ) ;
97
79
private readonly _cachedFrames : LRUMap < string , Promise < FrameVariables [ ] > > = new LRUMap ( 50 ) ;
80
+ private _stackParser : StackParser | undefined ;
98
81
99
82
/**
100
83
* @inheritDoc
@@ -103,22 +86,29 @@ export class LocalVariables implements Integration {
103
86
const options = getCurrentHub ( ) . getClient < NodeClient > ( ) ?. getOptions ( ) ;
104
87
105
88
if ( options ?. includeStackLocals ) {
106
- this . _stackHasher = createHashFn ( options . stackParser ) ;
107
- addGlobalEventProcessor ( async event => this . _addLocalVariables ( event ) ) ;
89
+ this . _stackParser = options . stackParser ;
108
90
109
91
this . _session . connect ( ) ;
110
92
this . _session . on ( 'Debugger.paused' , this . _handlePaused . bind ( this ) ) ;
111
93
this . _session . post ( 'Debugger.enable' ) ;
112
94
// We only want to pause on uncaught exceptions
113
95
this . _session . post ( 'Debugger.setPauseOnExceptions' , { state : 'uncaught' } ) ;
96
+
97
+ addGlobalEventProcessor ( async event => this . _addLocalVariables ( event ) ) ;
114
98
}
115
99
}
116
100
117
101
/**
118
102
* We use the stack parser to create a unique hash from the exception stack trace
119
- * This is used to lookup vars when the event processor is called
103
+ * This is used to lookup vars when the exception passes through the event processor
120
104
*/
121
- private _stackHasher : HashFromStackFn = _ => undefined ;
105
+ private _hashFromStack ( stack : string | undefined ) : string | undefined {
106
+ if ( this . _stackParser === undefined || stack === undefined ) {
107
+ return undefined ;
108
+ }
109
+
110
+ return hashFrames ( this . _stackParser ( stack , 1 ) ) ;
111
+ }
122
112
123
113
/**
124
114
* Handle the pause event
@@ -131,7 +121,7 @@ export class LocalVariables implements Integration {
131
121
}
132
122
133
123
// data.description contains the original error.stack
134
- const exceptionHash = this . _stackHasher ( data ?. description ) ;
124
+ const exceptionHash = this . _hashFromStack ( data ?. description ) ;
135
125
136
126
if ( exceptionHash == undefined ) {
137
127
return ;
@@ -219,7 +209,7 @@ export class LocalVariables implements Integration {
219
209
const frameCount = event ?. exception ?. values ?. [ 0 ] ?. stacktrace ?. frames ?. length || 0 ;
220
210
221
211
for ( let i = 0 ; i < frameCount ; i ++ ) {
222
- // Sentry frames are already in reverse order
212
+ // Sentry frames are in reverse order
223
213
const frameIndex = frameCount - i - 1 ;
224
214
225
215
// Drop out if we run out of frames to match up
0 commit comments