@@ -267,73 +267,77 @@ const _localVariablesSyncIntegration = ((
267
267
return {
268
268
name : INTEGRATION_NAME ,
269
269
setupOnce ( ) {
270
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
271
- AsyncSession . create ( sessionOverride ) . then ( session => {
272
- function handlePaused (
273
- stackParser : StackParser ,
274
- { params : { reason, data, callFrames } } : InspectorNotification < PausedExceptionEvent > ,
275
- complete : ( ) => void ,
276
- ) : void {
277
- if ( reason !== 'exception' && reason !== 'promiseRejection' ) {
278
- complete ( ) ;
279
- return ;
280
- }
270
+ const client = getClient < NodeClient > ( ) ;
271
+ const clientOptions = client ?. getOptions ( ) ;
281
272
282
- rateLimiter ?.( ) ;
273
+ if ( ! clientOptions ?. includeLocalVariables ) {
274
+ return ;
275
+ }
283
276
284
- // data.description contains the original error.stack
285
- const exceptionHash = hashFromStack ( stackParser , data ?. description ) ;
277
+ // Only setup this integration if the Node version is >= v18
278
+ // https://github.com/getsentry/sentry-javascript/issues/7697
279
+ const unsupportedNodeVersion = NODE_MAJOR < 18 ;
286
280
287
- if ( exceptionHash == undefined ) {
288
- complete ( ) ;
289
- return ;
290
- }
281
+ if ( unsupportedNodeVersion ) {
282
+ logger . log ( 'The `LocalVariables` integration is only supported on Node >= v18.' ) ;
283
+ return ;
284
+ }
291
285
292
- const { add, next } = createCallbackList < FrameVariables [ ] > ( frames => {
293
- cachedFrames . set ( exceptionHash , frames ) ;
294
- complete ( ) ;
295
- } ) ;
296
-
297
- // Because we're queuing up and making all these calls synchronously, we can potentially overflow the stack
298
- // For this reason we only attempt to get local variables for the first 5 frames
299
- for ( let i = 0 ; i < Math . min ( callFrames . length , 5 ) ; i ++ ) {
300
- const { scopeChain, functionName, this : obj } = callFrames [ i ] ;
301
-
302
- const localScope = scopeChain . find ( scope => scope . type === 'local' ) ;
303
-
304
- // obj.className is undefined in ESM modules
305
- const fn = obj . className === 'global' || ! obj . className ? functionName : `${ obj . className } .${ functionName } ` ;
306
-
307
- if ( localScope ?. object . objectId === undefined ) {
308
- add ( frames => {
309
- frames [ i ] = { function : fn } ;
310
- next ( frames ) ;
311
- } ) ;
312
- } else {
313
- const id = localScope . object . objectId ;
314
- add ( frames =>
315
- session ?. getLocalVariables ( id , vars => {
316
- frames [ i ] = { function : fn , vars } ;
317
- next ( frames ) ;
318
- } ) ,
319
- ) ;
286
+ AsyncSession . create ( sessionOverride ) . then (
287
+ session => {
288
+ function handlePaused (
289
+ stackParser : StackParser ,
290
+ { params : { reason, data, callFrames } } : InspectorNotification < PausedExceptionEvent > ,
291
+ complete : ( ) => void ,
292
+ ) : void {
293
+ if ( reason !== 'exception' && reason !== 'promiseRejection' ) {
294
+ complete ( ) ;
295
+ return ;
320
296
}
321
- }
322
297
323
- next ( [ ] ) ;
324
- }
298
+ rateLimiter ?.( ) ;
325
299
326
- const client = getClient < NodeClient > ( ) ;
327
- const clientOptions = client ?. getOptions ( ) ;
300
+ // data.description contains the original error.stack
301
+ const exceptionHash = hashFromStack ( stackParser , data ?. description ) ;
302
+
303
+ if ( exceptionHash == undefined ) {
304
+ complete ( ) ;
305
+ return ;
306
+ }
328
307
329
- if ( session && clientOptions ?. includeLocalVariables ) {
330
- // Only setup this integration if the Node version is >= v18
331
- // https://github.com/getsentry/sentry-javascript/issues/7697
332
- const unsupportedNodeVersion = NODE_MAJOR < 18 ;
308
+ const { add , next } = createCallbackList < FrameVariables [ ] > ( frames => {
309
+ cachedFrames . set ( exceptionHash , frames ) ;
310
+ complete ( ) ;
311
+ } ) ;
333
312
334
- if ( unsupportedNodeVersion ) {
335
- logger . log ( 'The `LocalVariables` integration is only supported on Node >= v18.' ) ;
336
- return ;
313
+ // Because we're queuing up and making all these calls synchronously, we can potentially overflow the stack
314
+ // For this reason we only attempt to get local variables for the first 5 frames
315
+ for ( let i = 0 ; i < Math . min ( callFrames . length , 5 ) ; i ++ ) {
316
+ const { scopeChain, functionName, this : obj } = callFrames [ i ] ;
317
+
318
+ const localScope = scopeChain . find ( scope => scope . type === 'local' ) ;
319
+
320
+ // obj.className is undefined in ESM modules
321
+ const fn =
322
+ obj . className === 'global' || ! obj . className ? functionName : `${ obj . className } .${ functionName } ` ;
323
+
324
+ if ( localScope ?. object . objectId === undefined ) {
325
+ add ( frames => {
326
+ frames [ i ] = { function : fn } ;
327
+ next ( frames ) ;
328
+ } ) ;
329
+ } else {
330
+ const id = localScope . object . objectId ;
331
+ add ( frames =>
332
+ session ?. getLocalVariables ( id , vars => {
333
+ frames [ i ] = { function : fn , vars } ;
334
+ next ( frames ) ;
335
+ } ) ,
336
+ ) ;
337
+ }
338
+ }
339
+
340
+ next ( [ ] ) ;
337
341
}
338
342
339
343
const captureAll = options . captureAllExceptions !== false ;
@@ -363,8 +367,11 @@ const _localVariablesSyncIntegration = ((
363
367
}
364
368
365
369
shouldProcessEvent = true ;
366
- }
367
- } ) ;
370
+ } ,
371
+ error => {
372
+ logger . log ( 'The `LocalVariables` integration failed to start.' , error ) ;
373
+ } ,
374
+ ) ;
368
375
} ,
369
376
processEvent ( event : Event ) : Event {
370
377
if ( shouldProcessEvent ) {
0 commit comments