Skip to content

Commit 36c0f26

Browse files
feat(node): Deprecate ANR integration (#16832)
resolves #16808 --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com>
1 parent 85f9bd0 commit 36c0f26

File tree

10 files changed

+101
-9
lines changed

10 files changed

+101
-9
lines changed

packages/astro/src/index.server.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ export {
1212
addEventProcessor,
1313
addIntegration,
1414
amqplibIntegration,
15+
// eslint-disable-next-line deprecation/deprecation
1516
anrIntegration,
17+
// eslint-disable-next-line deprecation/deprecation
1618
disableAnrDetectionForCallback,
1719
captureCheckIn,
1820
captureConsoleIntegration,

packages/aws-serverless/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ export {
4242
close,
4343
getSentryRelease,
4444
createGetModuleFromFilename,
45+
// eslint-disable-next-line deprecation/deprecation
4546
anrIntegration,
47+
// eslint-disable-next-line deprecation/deprecation
4648
disableAnrDetectionForCallback,
4749
consoleIntegration,
4850
httpIntegration,

packages/bun/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ export {
6262
close,
6363
getSentryRelease,
6464
createGetModuleFromFilename,
65+
// eslint-disable-next-line deprecation/deprecation
6566
anrIntegration,
67+
// eslint-disable-next-line deprecation/deprecation
6668
disableAnrDetectionForCallback,
6769
consoleIntegration,
6870
httpIntegration,

packages/google-cloud-serverless/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ export {
4242
close,
4343
getSentryRelease,
4444
createGetModuleFromFilename,
45+
// eslint-disable-next-line deprecation/deprecation
4546
anrIntegration,
47+
// eslint-disable-next-line deprecation/deprecation
4648
disableAnrDetectionForCallback,
4749
consoleIntegration,
4850
httpIntegration,

packages/node/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export { localVariablesIntegration } from './integrations/local-variables';
1010
export { modulesIntegration } from './integrations/modules';
1111
export { onUncaughtExceptionIntegration } from './integrations/onuncaughtexception';
1212
export { onUnhandledRejectionIntegration } from './integrations/onunhandledrejection';
13+
// eslint-disable-next-line deprecation/deprecation
1314
export { anrIntegration, disableAnrDetectionForCallback } from './integrations/anr';
1415

1516
export { expressIntegration, expressErrorHandler, setupExpressErrorHandler } from './integrations/tracing/express';

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

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,77 @@
11
import type { Contexts, DsnComponents, Primitive, SdkMetadata } from '@sentry/core';
22

3+
/**
4+
* Configuration options for the ANR (Application Not Responding) integration.
5+
*
6+
* These options control how the ANR detection system monitors the Node.js event loop
7+
* and reports blocking events.
8+
*
9+
* @deprecated The ANR integration has been deprecated. Use `eventLoopBlockIntegration` from `@sentry/node-native` instead.
10+
*/
311
export interface AnrIntegrationOptions {
412
/**
5-
* Interval to send heartbeat messages to the ANR worker.
13+
* Interval to send heartbeat messages to the ANR worker thread.
614
*
7-
* Defaults to 50ms.
15+
* The main thread sends heartbeat messages to the worker thread at this interval
16+
* to indicate that the event loop is still responsive. Lower values provide more
17+
* precise detection but may increase overhead.
18+
*
19+
* @default 50 (milliseconds)
820
*/
921
pollInterval: number;
22+
1023
/**
1124
* Threshold in milliseconds to trigger an ANR event.
1225
*
13-
* Defaults to 5000ms.
26+
* When the worker thread doesn't receive a heartbeat message for this duration,
27+
* it considers the main thread to be blocked and triggers an ANR event.
28+
*
29+
* @default 5000 (milliseconds)
1430
*/
1531
anrThreshold: number;
32+
1633
/**
1734
* Whether to capture a stack trace when the ANR event is triggered.
1835
*
19-
* Defaults to `false`.
36+
* When enabled, uses the Node.js inspector API to capture the stack trace
37+
* of the blocking code. This provides more detailed information about what
38+
* caused the ANR but requires the debugger to be enabled.
39+
*
40+
* **Note:** This opens the inspector API and required ports.
2041
*
21-
* This uses the node debugger which enables the inspector API and opens the required ports.
42+
* @default false
2243
*/
2344
captureStackTrace: boolean;
45+
2446
/**
25-
* Maximum number of ANR events to send.
47+
* Maximum number of ANR events to send per application session.
48+
*
49+
* Once this limit is reached, the ANR worker thread will exit to prevent
50+
* sending duplicate events. This helps avoid spamming Sentry with repeated
51+
* ANR events from the same blocking issue.
2652
*
27-
* Defaults to 1.
53+
* @default 1
2854
*/
2955
maxAnrEvents: number;
56+
3057
/**
31-
* Tags to include with ANR events.
58+
* Static tags to include with all ANR events.
59+
*
60+
* These tags will be attached to every ANR event sent by this integration,
61+
* useful for categorizing or filtering ANR events in Sentry.
3262
*/
3363
staticTags: { [key: string]: Primitive };
64+
3465
/**
3566
* @ignore Internal use only.
3667
*
3768
* If this is supplied, stack frame filenames will be rewritten to be relative to this path.
69+
* This is used internally for better stack trace readability.
3870
*/
3971
appRootPath: string | undefined;
4072
}
4173

74+
// eslint-disable-next-line deprecation/deprecation
4275
export interface WorkerStartData extends AnrIntegrationOptions {
4376
debug: boolean;
4477
sdkMetadata: SdkMetadata;

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

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ const INTEGRATION_NAME = 'Anr';
6666

6767
type AnrInternal = { startWorker: () => void; stopWorker: () => void };
6868

69+
// eslint-disable-next-line deprecation/deprecation
6970
const _anrIntegration = ((options: Partial<AnrIntegrationOptions> = {}) => {
7071
if (NODE_VERSION.major < 16 || (NODE_VERSION.major === 16 && NODE_VERSION.minor < 17)) {
7172
throw new Error('ANR detection requires Node 16.17.0 or later');
@@ -114,8 +115,45 @@ const _anrIntegration = ((options: Partial<AnrIntegrationOptions> = {}) => {
114115
} as Integration & AnrInternal;
115116
}) satisfies IntegrationFn;
116117

118+
// eslint-disable-next-line deprecation/deprecation
117119
type AnrReturn = (options?: Partial<AnrIntegrationOptions>) => Integration & AnrInternal;
118120

121+
/**
122+
* Application Not Responding (ANR) integration for Node.js applications.
123+
*
124+
* @deprecated The ANR integration has been deprecated. Use `eventLoopBlockIntegration` from `@sentry/node-native` instead.
125+
*
126+
* Detects when the Node.js main thread event loop is blocked for more than the configured
127+
* threshold (5 seconds by default) and reports these as Sentry events.
128+
*
129+
* ANR detection uses a worker thread to monitor the event loop in the main app thread.
130+
* The main app thread sends a heartbeat message to the ANR worker thread every 50ms by default.
131+
* If the ANR worker does not receive a heartbeat message for the configured threshold duration,
132+
* it triggers an ANR event.
133+
*
134+
* - Node.js 16.17.0 or higher
135+
* - Only supported in the Node.js runtime (not browsers)
136+
* - Not supported for Node.js clusters
137+
*
138+
* Overhead should be minimal:
139+
* - Main thread: Only polling the ANR worker over IPC every 50ms
140+
* - Worker thread: Consumes around 10-20 MB of RAM
141+
* - When ANR detected: Brief pause in debugger to capture stack trace (negligible compared to the blocking)
142+
*
143+
* @example
144+
* ```javascript
145+
* Sentry.init({
146+
* dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
147+
* integrations: [
148+
* Sentry.anrIntegration({
149+
* anrThreshold: 5000,
150+
* captureStackTrace: true,
151+
* pollInterval: 50,
152+
* }),
153+
* ],
154+
* });
155+
* ```
156+
*/
119157
export const anrIntegration = defineIntegration(_anrIntegration) as AnrReturn;
120158

121159
/**
@@ -125,6 +163,7 @@ export const anrIntegration = defineIntegration(_anrIntegration) as AnrReturn;
125163
*/
126164
async function _startWorker(
127165
client: NodeClient,
166+
// eslint-disable-next-line deprecation/deprecation
128167
integrationOptions: Partial<AnrIntegrationOptions>,
129168
): Promise<() => void> {
130169
const dsn = client.getDsn();
@@ -229,7 +268,13 @@ async function _startWorker(
229268
export function disableAnrDetectionForCallback<T>(callback: () => T): T;
230269
export function disableAnrDetectionForCallback<T>(callback: () => Promise<T>): Promise<T>;
231270
/**
232-
* Disables ANR detection for the duration of the callback
271+
* Temporarily disables ANR detection for the duration of a callback function.
272+
*
273+
* This utility function allows you to disable ANR detection during operations that
274+
* are expected to block the event loop, such as intensive computational tasks or
275+
* synchronous I/O operations.
276+
*
277+
* @deprecated The ANR integration has been deprecated. Use `eventLoopBlockIntegration` from `@sentry/node-native` instead.
233278
*/
234279
export function disableAnrDetectionForCallback<T>(callback: () => T | Promise<T>): T | Promise<T> {
235280
const integration = getClient()?.getIntegrationByName(INTEGRATION_NAME) as AnrInternal | undefined;

packages/remix/src/server/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export {
55
addEventProcessor,
66
addIntegration,
77
amqplibIntegration,
8+
// eslint-disable-next-line deprecation/deprecation
89
anrIntegration,
910
disableAnrDetectionForCallback,
1011
captureCheckIn,

packages/solidstart/src/server/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ export {
88
addEventProcessor,
99
addIntegration,
1010
amqplibIntegration,
11+
// eslint-disable-next-line deprecation/deprecation
1112
anrIntegration,
13+
// eslint-disable-next-line deprecation/deprecation
1214
disableAnrDetectionForCallback,
1315
captureCheckIn,
1416
captureConsoleIntegration,

packages/sveltekit/src/server/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ export {
88
addEventProcessor,
99
addIntegration,
1010
amqplibIntegration,
11+
// eslint-disable-next-line deprecation/deprecation
1112
anrIntegration,
13+
// eslint-disable-next-line deprecation/deprecation
1214
disableAnrDetectionForCallback,
1315
captureCheckIn,
1416
captureConsoleIntegration,

0 commit comments

Comments
 (0)