Skip to content

Commit 034be00

Browse files
committed
Use inspector.url()
1 parent cc18077 commit 034be00

File tree

4 files changed

+29
-15
lines changed

4 files changed

+29
-15
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,6 @@ const _anrIntegration = ((options: Partial<AnrIntegrationOptions> = {}) => {
7474
let worker: Promise<() => void> | undefined;
7575
let client: NodeClient | undefined;
7676

77-
if (isDebuggerEnabled() && options.captureStackTrace) {
78-
logger.warn('ANR captureStackTrace has been disabled because the debugger is enabled');
79-
options.captureStackTrace = false;
80-
}
81-
8277
// Hookup the scope fetch function to the global object so that it can be called from the worker thread via the
8378
// debugger when it pauses
8479
const gbl = globalWithScopeFetchFn();
@@ -104,9 +99,14 @@ const _anrIntegration = ((options: Partial<AnrIntegrationOptions> = {}) => {
10499
});
105100
}
106101
},
107-
setup(initClient: NodeClient) {
102+
async setup(initClient: NodeClient) {
108103
client = initClient;
109104

105+
if (options.captureStackTrace && (await isDebuggerEnabled())) {
106+
logger.warn('ANR captureStackTrace has been disabled because the debugger was already enabled');
107+
options.captureStackTrace = false;
108+
}
109+
110110
// setImmediate is used to ensure that all other integrations have had their setup called first.
111111
// This allows us to call into all integrations to fetch the full context
112112
setImmediate(() => this.startWorker());

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,16 @@ export const localVariablesAsyncIntegration = defineIntegration(((
102102

103103
return {
104104
name: 'LocalVariablesAsync',
105-
setup(client: NodeClient) {
105+
async setup(client: NodeClient) {
106106
const clientOptions = client.getOptions();
107107

108108
if (!clientOptions.includeLocalVariables) {
109109
return;
110110
}
111111

112-
if (isDebuggerEnabled()) {
113-
logger.warn('Local variables capture has been disabled because the debugger is enabled');
112+
if (await isDebuggerEnabled()) {
113+
logger.warn('Local variables capture has been disabled because the debugger was already enabled');
114+
return;
114115
}
115116

116117
const options: LocalVariablesWorkerArgs = {

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ const _localVariablesSyncIntegration = ((
290290

291291
return {
292292
name: INTEGRATION_NAME,
293-
setupOnce() {
293+
async setupOnce() {
294294
const client = getClient<NodeClient>();
295295
const clientOptions = client?.getOptions();
296296

@@ -307,8 +307,9 @@ const _localVariablesSyncIntegration = ((
307307
return;
308308
}
309309

310-
if (isDebuggerEnabled()) {
311-
logger.warn('Local variables capture has been disabled because the debugger is enabled');
310+
if (await isDebuggerEnabled()) {
311+
logger.warn('Local variables capture has been disabled because the debugger was already enabled');
312+
return;
312313
}
313314

314315
AsyncSession.create(sessionOverride).then(

packages/node/src/utils/debug.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
1+
let cachedDebuggerEnabled: boolean | undefined;
2+
13
/**
2-
* Has the debugger been enabled via the command line?
4+
* Was the debugger enabled when this function was first called?
35
*/
4-
export function isDebuggerEnabled(): boolean {
5-
return process.execArgv.some(arg => arg.startsWith('--inspect'));
6+
export async function isDebuggerEnabled(): Promise<boolean> {
7+
if (cachedDebuggerEnabled === undefined) {
8+
try {
9+
// Node can be built without inspector support
10+
const inspector = await import('node:inspector');
11+
cachedDebuggerEnabled = !!inspector.url();
12+
} catch (_) {
13+
cachedDebuggerEnabled = false;
14+
}
15+
}
16+
17+
return cachedDebuggerEnabled;
618
}

0 commit comments

Comments
 (0)