Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions dev-packages/node-integration-tests/suites/anr/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,35 @@ const ANR_EVENT = {
},
};

const ANR_EVENT_WITHOUT_STACKTRACE = {
// Ensure we have context
contexts: {
device: {
arch: expect.any(String),
},
app: {
app_start_time: expect.any(String),
},
os: {
name: expect.any(String),
},
culture: {
timezone: expect.any(String),
},
},
// and an exception that is our ANR
exception: {
values: [
{
type: 'ApplicationNotResponding',
value: 'Application Not Responding for at least 100 ms',
mechanism: { type: 'ANR' },
stacktrace: {},
},
],
},
};

const ANR_EVENT_WITH_SCOPE = {
...ANR_EVENT,
user: {
Expand Down Expand Up @@ -98,11 +127,11 @@ conditionalTest({ min: 16 })('should report ANR when event loop blocked', () =>
createRunner(__dirname, 'indefinite.mjs').withMockSentryServer().expect({ event: ANR_EVENT }).start(done);
});

test('With --inspect', done => {
test("With --inspect the debugger isn't used", done => {
createRunner(__dirname, 'basic.mjs')
.withMockSentryServer()
.withFlags('--inspect')
.expect({ event: ANR_EVENT_WITH_SCOPE })
.expect({ event: ANR_EVENT_WITHOUT_STACKTRACE })
.start(done);
});

Expand Down
6 changes: 6 additions & 0 deletions packages/node/src/integrations/anr/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
} from '@sentry/core';
import { NODE_VERSION } from '../../nodeVersion';
import type { NodeClient } from '../../sdk/client';
import { isDebuggerEnabled } from '../../utils/debug';
import type { AnrIntegrationOptions, WorkerStartData } from './common';

const { isPromise } = types;
Expand Down Expand Up @@ -73,6 +74,11 @@ const _anrIntegration = ((options: Partial<AnrIntegrationOptions> = {}) => {
let worker: Promise<() => void> | undefined;
let client: NodeClient | undefined;

if (isDebuggerEnabled() && options.captureStackTrace) {
logger.warn('ANR captureStackTrace has been disabled because the debugger is enabled');
options.captureStackTrace = false;
}

// Hookup the scope fetch function to the global object so that it can be called from the worker thread via the
// debugger when it pauses
const gbl = globalWithScopeFetchFn();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Worker } from 'node:worker_threads';
import type { Event, EventHint, Exception, IntegrationFn } from '@sentry/core';
import { defineIntegration, logger } from '@sentry/core';
import type { NodeClient } from '../../sdk/client';
import { isDebuggerEnabled } from '../../utils/debug';
import type { FrameVariables, LocalVariablesIntegrationOptions, LocalVariablesWorkerArgs } from './common';
import { LOCAL_VARIABLES_KEY, functionNamesMatch } from './common';

Expand Down Expand Up @@ -108,6 +109,10 @@ export const localVariablesAsyncIntegration = defineIntegration(((
return;
}

if (isDebuggerEnabled()) {
logger.warn('Local variables capture has been disabled because the debugger is enabled');
}

const options: LocalVariablesWorkerArgs = {
...integrationOptions,
debug: logger.isEnabled(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { Event, Exception, IntegrationFn, StackFrame, StackParser } from '@
import { LRUMap, defineIntegration, getClient, logger } from '@sentry/core';
import { NODE_MAJOR } from '../../nodeVersion';
import type { NodeClient } from '../../sdk/client';
import { isDebuggerEnabled } from '../../utils/debug';
import type {
FrameVariables,
LocalVariablesIntegrationOptions,
Expand Down Expand Up @@ -306,6 +307,10 @@ const _localVariablesSyncIntegration = ((
return;
}

if (isDebuggerEnabled()) {
logger.warn('Local variables capture has been disabled because the debugger is enabled');
}

AsyncSession.create(sessionOverride).then(
session => {
function handlePaused(
Expand Down
6 changes: 6 additions & 0 deletions packages/node/src/utils/debug.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* Has the debugger been enabled via the command line?
*/
export function isDebuggerEnabled(): boolean {
return process.execArgv.some(arg => arg.startsWith('--inspect'));
}
Loading