Skip to content

Commit e69226e

Browse files
committed
fix: Disable ANR and Local Variables if debugger is enabled via CLI args
1 parent a9dcdb8 commit e69226e

File tree

5 files changed

+27
-0
lines changed

5 files changed

+27
-0
lines changed

dev-packages/node-integration-tests/suites/anr/test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ conditionalTest({ min: 16 })('should report ANR when event loop blocked', () =>
9999
});
100100

101101
test('With --inspect', done => {
102+
const ANR_EVENT_NO_STACKTRACE = { ...ANR_EVENT };
103+
if (ANR_EVENT_NO_STACKTRACE?.exception?.values?.[0]?.stacktrace) {
104+
(ANR_EVENT_NO_STACKTRACE.exception.values[0].stacktrace as any) = {};
105+
}
106+
102107
createRunner(__dirname, 'basic.mjs')
103108
.withMockSentryServer()
104109
.withFlags('--inspect')

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
import { NODE_VERSION } from '../../nodeVersion';
1616
import type { NodeClient } from '../../sdk/client';
1717
import type { AnrIntegrationOptions, WorkerStartData } from './common';
18+
import { isDebuggerEnabled } from '../../utils/debug';
1819

1920
const { isPromise } = types;
2021

@@ -73,6 +74,11 @@ const _anrIntegration = ((options: Partial<AnrIntegrationOptions> = {}) => {
7374
let worker: Promise<() => void> | undefined;
7475
let client: NodeClient | undefined;
7576

77+
if (isDebuggerEnabled() && options.captureStackTrace) {
78+
logger.warn('ANR captureStackTrace has been disabled because the debugger is enabled');
79+
options.captureStackTrace = false;
80+
}
81+
7682
// Hookup the scope fetch function to the global object so that it can be called from the worker thread via the
7783
// debugger when it pauses
7884
const gbl = globalWithScopeFetchFn();

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { defineIntegration, logger } from '@sentry/core';
44
import type { NodeClient } from '../../sdk/client';
55
import type { FrameVariables, LocalVariablesIntegrationOptions, LocalVariablesWorkerArgs } from './common';
66
import { LOCAL_VARIABLES_KEY, functionNamesMatch } from './common';
7+
import { isDebuggerEnabled } from '../../utils/debug';
78

89
// This string is a placeholder that gets overwritten with the worker code.
910
export const base64WorkerScript = '###LocalVariablesWorkerScript###';
@@ -108,6 +109,10 @@ export const localVariablesAsyncIntegration = defineIntegration(((
108109
return;
109110
}
110111

112+
if (isDebuggerEnabled()) {
113+
logger.warn('Local variables capture has been disabled because the debugger is enabled');
114+
}
115+
111116
const options: LocalVariablesWorkerArgs = {
112117
...integrationOptions,
113118
debug: logger.isEnabled(),

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import type {
1111
Variables,
1212
} from './common';
1313
import { createRateLimiter, functionNamesMatch } from './common';
14+
import { isDebuggerEnabled } from '../../utils/debug';
1415

1516
/** Creates a unique hash from stack frames */
1617
export function hashFrames(frames: StackFrame[] | undefined): string | undefined {
@@ -306,6 +307,10 @@ const _localVariablesSyncIntegration = ((
306307
return;
307308
}
308309

310+
if (isDebuggerEnabled()) {
311+
logger.warn('Local variables capture has been disabled because the debugger is enabled');
312+
}
313+
309314
AsyncSession.create(sessionOverride).then(
310315
session => {
311316
function handlePaused(

packages/node/src/utils/debug.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* Has the debugger been enabled via the command line?
3+
*/
4+
export function isDebuggerEnabled(): boolean {
5+
return process.execArgv.some(arg => arg.startsWith('--inspect'));
6+
}

0 commit comments

Comments
 (0)