Skip to content

feat(node): Send ANR events from main thread #11525

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ setTimeout(() => {
Sentry.init({
dsn: process.env.SENTRY_DSN,
release: '1.0',
integrations: [Sentry.anrIntegration({ captureStackTrace: true, anrThreshold: 100 })],
integrations: [Sentry.anrIntegration({ anrThreshold: 100 })],
autoSessionTracking: true,
});

Expand Down
2 changes: 1 addition & 1 deletion dev-packages/node-integration-tests/suites/anr/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Sentry.init({
dsn: process.env.SENTRY_DSN,
release: '1.0',
autoSessionTracking: false,
integrations: [Sentry.anrIntegration({ captureStackTrace: true, anrThreshold: 100 })],
integrations: [Sentry.anrIntegration({ anrThreshold: 100 })],
});

Sentry.setUser({ email: 'person@home.com' });
Expand Down
2 changes: 1 addition & 1 deletion dev-packages/node-integration-tests/suites/anr/basic.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Sentry.init({
dsn: process.env.SENTRY_DSN,
release: '1.0',
autoSessionTracking: false,
integrations: [Sentry.anrIntegration({ captureStackTrace: true, anrThreshold: 100 })],
integrations: [Sentry.anrIntegration({ anrThreshold: 100 })],
});

Sentry.setUser({ email: 'person@home.com' });
Expand Down
4 changes: 2 additions & 2 deletions dev-packages/node-integration-tests/suites/anr/forked.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ setTimeout(() => {
}, 10000);

Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
dsn: process.env.SENTRY_DSN,
release: '1.0',
autoSessionTracking: false,
debug: true,
integrations: [Sentry.anrIntegration({ captureStackTrace: true, anrThreshold: 100 })],
integrations: [Sentry.anrIntegration({ anrThreshold: 100 })],
});

Sentry.setUser({ email: 'person@home.com' });
Expand Down
2 changes: 1 addition & 1 deletion dev-packages/node-integration-tests/suites/anr/forker.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { fork } = require('child_process');
const { join } = require('path');

const child = fork(join(__dirname, 'forked.js'), { stdio: 'inherit' });
const child = fork(join(__dirname, 'forked.js'), { stdio: 'inherit', env: process.env });
child.on('exit', () => {
process.exit();
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Sentry.init({
dsn: process.env.SENTRY_DSN,
release: '1.0',
autoSessionTracking: false,
integrations: [Sentry.anrIntegration({ captureStackTrace: true, anrThreshold: 100 })],
integrations: [Sentry.anrIntegration({ anrThreshold: 100 })],
});

async function longWork() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ const Sentry = require('@sentry/node');

function configureSentry() {
Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
dsn: process.env.SENTRY_DSN,
release: '1.0',
autoSessionTracking: false,
debug: true,
integrations: [Sentry.anrIntegration({ captureStackTrace: true })],
integrations: [Sentry.anrIntegration()],
});
}

Expand Down
4 changes: 2 additions & 2 deletions dev-packages/node-integration-tests/suites/anr/should-exit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ const Sentry = require('@sentry/node');

function configureSentry() {
Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
dsn: process.env.SENTRY_DSN,
release: '1.0',
autoSessionTracking: false,
debug: true,
integrations: [Sentry.anrIntegration({ captureStackTrace: true })],
integrations: [Sentry.anrIntegration()],
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ setTimeout(() => {
process.exit();
}, 10000);

const anr = Sentry.anrIntegration({ captureStackTrace: true, anrThreshold: 100 });
const anr = Sentry.anrIntegration({ anrThreshold: 100 });

Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
dsn: process.env.SENTRY_DSN,
release: '1.0',
debug: true,
autoSessionTracking: false,
Expand Down
23 changes: 13 additions & 10 deletions dev-packages/node-integration-tests/suites/anr/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,20 @@ const EXPECTED_ANR_EVENT = {
mechanism: { type: 'ANR' },
stacktrace: {
frames: expect.arrayContaining([
{
expect.objectContaining({
colno: expect.any(Number),
lineno: expect.any(Number),
filename: expect.any(String),
function: '?',
in_app: true,
},
{
}),
expect.objectContaining({
colno: expect.any(Number),
lineno: expect.any(Number),
filename: expect.any(String),
function: 'longWork',
in_app: true,
},
}),
]),
},
},
Expand Down Expand Up @@ -82,7 +82,7 @@ conditionalTest({ min: 16 })('should report ANR when event loop blocked', () =>
});

test('should exit', done => {
const runner = createRunner(__dirname, 'should-exit.js').start();
const runner = createRunner(__dirname, 'should-exit.js').withMockSentryServer().start();

setTimeout(() => {
expect(runner.childHasExited()).toBe(true);
Expand All @@ -91,7 +91,7 @@ conditionalTest({ min: 16 })('should report ANR when event loop blocked', () =>
});

test('should exit forced', done => {
const runner = createRunner(__dirname, 'should-exit-forced.js').start();
const runner = createRunner(__dirname, 'should-exit-forced.js').withMockSentryServer().start();

setTimeout(() => {
expect(runner.childHasExited()).toBe(true);
Expand All @@ -113,11 +113,14 @@ conditionalTest({ min: 16 })('should report ANR when event loop blocked', () =>
});

test('from forked process', done => {
createRunner(__dirname, 'forker.js').expect({ event: EXPECTED_ANR_EVENT }).start(done);
createRunner(__dirname, 'forker.js').withMockSentryServer().expect({ event: EXPECTED_ANR_EVENT }).start(done);
});

test('worker can be stopped and restarted', done => {
createRunner(__dirname, 'stop-and-start.js').expect({ event: EXPECTED_ANR_EVENT }).start(done);
createRunner(__dirname, 'stop-and-start.js')
.withMockSentryServer()
.expect({ event: EXPECTED_ANR_EVENT })
.start(done);
});

const EXPECTED_ISOLATED_EVENT = {
Expand All @@ -132,13 +135,13 @@ conditionalTest({ min: 16 })('should report ANR when event loop blocked', () =>
mechanism: { type: 'ANR' },
stacktrace: {
frames: expect.arrayContaining([
{
expect.objectContaining({
colno: expect.any(Number),
lineno: expect.any(Number),
filename: expect.stringMatching(/isolated.mjs$/),
function: 'longWork',
in_app: true,
},
}),
]),
},
},
Expand Down
17 changes: 1 addition & 16 deletions packages/node/src/integrations/anr/common.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Contexts, DsnComponents, Primitive, SdkMetadata } from '@sentry/types';
import type { Primitive } from '@sentry/types';

export interface AnrIntegrationOptions {
/**
Expand All @@ -13,14 +13,6 @@ export interface AnrIntegrationOptions {
* Defaults to 5000ms.
*/
anrThreshold: number;
/**
* Whether to capture a stack trace when the ANR event is triggered.
*
* Defaults to `false`.
*
* This uses the node debugger which enables the inspector API and opens the required ports.
*/
captureStackTrace: boolean;
/**
* Tags to include with ANR events.
*/
Expand All @@ -35,11 +27,4 @@ export interface AnrIntegrationOptions {

export interface WorkerStartData extends AnrIntegrationOptions {
debug: boolean;
sdkMetadata: SdkMetadata;
dsn: DsnComponents;
tunnel: string | undefined;
release: string | undefined;
environment: string;
dist: string | undefined;
contexts: Contexts;
}
Loading