@@ -117,7 +117,55 @@ const _anrIntegration = ((options: Partial<AnrIntegrationOptions> = {}) => {
117117type AnrReturn = ( options ?: Partial < AnrIntegrationOptions > ) => Integration & AnrInternal ;
118118
119119/**
120+ * Application Not Responding (ANR) integration for Node.js applications.
121+ *
122+ * Detects when the Node.js main thread event loop is blocked for more than the configured
123+ * threshold (5 seconds by default) and reports these as Sentry events.
124+ *
125+ * ## How it works
126+ *
127+ * ANR detection uses a worker thread to monitor the event loop in the main app thread.
128+ * The main app thread sends a heartbeat message to the ANR worker thread every 50ms by default.
129+ * If the ANR worker does not receive a heartbeat message for the configured threshold duration,
130+ * it triggers an ANR event.
131+ *
132+ * ## Requirements
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+ * ## Performance Impact
139+ *
140+ * Overhead should be minimal:
141+ * - Main thread: Only polling the ANR worker over IPC every 50ms
142+ * - Worker thread: Consumes around 10-20 MB of RAM
143+ * - When ANR detected: Brief pause in debugger to capture stack trace (negligible compared to the blocking)
144+ *
145+ * ## Configuration Options
146+ *
147+ * - `pollInterval`: Interval to send heartbeat messages (default: 50ms)
148+ * - `anrThreshold`: Threshold in milliseconds to trigger an ANR event (default: 5000ms)
149+ * - `captureStackTrace`: Whether to capture stack traces using the Node.js inspector API (default: false)
150+ * - `maxAnrEvents`: Maximum number of ANR events to send (default: 1)
151+ * - `staticTags`: Tags to include with ANR events
152+ *
153+ * @example
154+ * ```javascript
155+ * Sentry.init({
156+ * dsn: "https://examplePublicKey@o 0.ingest.sentry.io/0",
157+ * integrations: [
158+ * Sentry.anrIntegration({
159+ * anrThreshold: 5000,
160+ * captureStackTrace: true,
161+ * pollInterval: 50,
162+ * }),
163+ * ],
164+ * });
165+ * ```
166+ *
120167 * @deprecated The ANR integration has been deprecated. Use `eventLoopBlockIntegration` from `@sentry/node-native` instead.
168+ * @see {@link https://docs.sentry.io/platforms/javascript/guides/nextjs/configuration/application-not-responding/ }
121169 */
122170export const anrIntegration = defineIntegration ( _anrIntegration ) as AnrReturn ;
123171
@@ -232,8 +280,48 @@ async function _startWorker(
232280export function disableAnrDetectionForCallback < T > ( callback : ( ) => T ) : T ;
233281export function disableAnrDetectionForCallback < T > ( callback : ( ) => Promise < T > ) : Promise < T > ;
234282/**
235- * Disables ANR detection for the duration of the callback
283+ * Temporarily disables ANR detection for the duration of a callback function.
284+ *
285+ * This utility function allows you to disable ANR detection during operations that
286+ * are expected to block the event loop, such as intensive computational tasks or
287+ * synchronous I/O operations.
288+ *
289+ * ## Use Cases
290+ *
291+ * - CPU-intensive operations that legitimately block the event loop
292+ * - Synchronous file operations or database queries
293+ * - Intentional blocking operations during application startup
294+ * - Long-running computations that should not trigger ANR events
295+ *
296+ * ## Behavior
297+ *
298+ * - **Synchronous callbacks**: ANR detection is disabled before the callback runs
299+ * and re-enabled immediately after it completes
300+ * - **Asynchronous callbacks**: ANR detection is disabled before the callback runs
301+ * and re-enabled after the Promise resolves or rejects
302+ * - **No ANR integration**: If the ANR integration is not active, the callback
303+ * runs normally without any modifications
304+ *
305+ * @example
306+ * ```javascript
307+ * // For synchronous operations
308+ * const result = disableAnrDetectionForCallback(() => {
309+ * // Perform CPU-intensive work that might block for several seconds
310+ * return performHeavyComputation();
311+ * });
312+ *
313+ * // For asynchronous operations
314+ * const result = await disableAnrDetectionForCallback(async () => {
315+ * // Perform async work without ANR detection
316+ * return await heavyAsyncOperation();
317+ * });
318+ * ```
319+ *
320+ * @param callback - The function to execute with ANR detection disabled
321+ * @returns The result of the callback function
322+ *
236323 * @deprecated The ANR integration has been deprecated. Use `eventLoopBlockIntegration` from `@sentry/node-native` instead.
324+ * @see {@link https://docs.sentry.io/platforms/javascript/guides/nextjs/configuration/application-not-responding/ }
237325 */
238326export function disableAnrDetectionForCallback < T > ( callback : ( ) => T | Promise < T > ) : T | Promise < T > {
239327 const integration = getClient ( ) ?. getIntegrationByName ( INTEGRATION_NAME ) as AnrInternal | undefined ;
0 commit comments