Skip to content

Commit 8d3bae0

Browse files
committed
Don't start if its not enabled
1 parent 60378d4 commit 8d3bae0

File tree

2 files changed

+68
-61
lines changed

2 files changed

+68
-61
lines changed

packages/node/src/integrations/anr/worker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Session as InspectorSession } from 'node:inspector';
12
import { parentPort, workerData } from 'node:worker_threads';
23
import {
34
applyScopeDataToEvent,
@@ -15,7 +16,6 @@ import {
1516
uuid4,
1617
watchdogTimer,
1718
} from '@sentry/utils';
18-
import { Session as InspectorSession } from 'node:inspector';
1919

2020
import { makeNodeTransport } from '../../transports';
2121
import { createGetModuleFromFilename } from '../../utils/module';

packages/node/src/integrations/local-variables/local-variables-sync.ts

Lines changed: 67 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -267,73 +267,77 @@ const _localVariablesSyncIntegration = ((
267267
return {
268268
name: INTEGRATION_NAME,
269269
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();
281272

282-
rateLimiter?.();
273+
if (!clientOptions?.includeLocalVariables) {
274+
return;
275+
}
283276

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;
286280

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+
}
291285

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;
320296
}
321-
}
322297

323-
next([]);
324-
}
298+
rateLimiter?.();
325299

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+
}
328307

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+
});
333312

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([]);
337341
}
338342

339343
const captureAll = options.captureAllExceptions !== false;
@@ -363,8 +367,11 @@ const _localVariablesSyncIntegration = ((
363367
}
364368

365369
shouldProcessEvent = true;
366-
}
367-
});
370+
},
371+
error => {
372+
logger.log('The `LocalVariables` integration failed to start.', error);
373+
},
374+
);
368375
},
369376
processEvent(event: Event): Event {
370377
if (shouldProcessEvent) {

0 commit comments

Comments
 (0)