@sentry/node-native 9.38.0 → 9.40.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/event-loop-block-integration.js +174 -77
- package/build/cjs/event-loop-block-integration.js.map +1 -1
- package/build/cjs/event-loop-block-watchdog.js +1 -1
- package/build/cjs/event-loop-block-watchdog.js.map +1 -1
- package/build/cjs/index.js +3 -0
- package/build/cjs/index.js.map +1 -1
- package/build/esm/event-loop-block-integration.js +174 -80
- package/build/esm/event-loop-block-integration.js.map +1 -1
- package/build/esm/event-loop-block-watchdog.js +1 -1
- package/build/esm/event-loop-block-watchdog.js.map +1 -1
- package/build/esm/index.js +1 -1
- package/build/esm/package.json +1 -1
- package/build/types/event-loop-block-integration.d.ts +16 -1
- package/build/types/event-loop-block-integration.d.ts.map +1 -1
- package/build/types/index.d.ts +1 -1
- package/build/types/index.d.ts.map +1 -1
- package/build/types-ts3.8/event-loop-block-integration.d.ts +16 -1
- package/build/types-ts3.8/index.d.ts +1 -1
- package/package.json +4 -4
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
|
|
3
|
+
const types = require('node:util/types');
|
|
3
4
|
const node_worker_threads = require('node:worker_threads');
|
|
4
5
|
const core = require('@sentry/core');
|
|
5
6
|
const nodeNativeStacktrace = require('@sentry-internal/node-native-stacktrace');
|
|
6
7
|
const common = require('./common.js');
|
|
7
8
|
|
|
8
9
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
10
|
+
const INTEGRATION_NAME = 'ThreadBlocked';
|
|
9
11
|
const DEFAULT_THRESHOLD_MS = 1000;
|
|
10
12
|
|
|
11
13
|
function log(message, ...args) {
|
|
12
|
-
core.
|
|
14
|
+
core.debug.log(`[Sentry Event Loop Blocked] ${message}`, ...args);
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
/**
|
|
@@ -27,68 +29,59 @@ async function getContexts(client) {
|
|
|
27
29
|
return event?.contexts || {};
|
|
28
30
|
}
|
|
29
31
|
|
|
30
|
-
|
|
32
|
+
function poll(enabled, clientOptions) {
|
|
33
|
+
try {
|
|
34
|
+
const currentSession = core.getIsolationScope().getSession();
|
|
35
|
+
// We need to copy the session object and remove the toJSON method so it can be sent to the worker
|
|
36
|
+
// serialized without making it a SerializedSession
|
|
37
|
+
const session = currentSession ? { ...currentSession, toJSON: undefined } : undefined;
|
|
38
|
+
// message the worker to tell it the main event loop is still running
|
|
39
|
+
nodeNativeStacktrace.threadPoll({ session, debugImages: core.getFilenameToDebugIdMap(clientOptions.stackParser) }, !enabled);
|
|
40
|
+
} catch {
|
|
41
|
+
// we ignore all errors
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Starts polling
|
|
47
|
+
*/
|
|
48
|
+
function startPolling(
|
|
49
|
+
client,
|
|
50
|
+
integrationOptions,
|
|
51
|
+
) {
|
|
52
|
+
nodeNativeStacktrace.registerThread();
|
|
53
|
+
|
|
54
|
+
let enabled = true;
|
|
55
|
+
|
|
56
|
+
const initOptions = client.getOptions();
|
|
57
|
+
const pollInterval = (integrationOptions.threshold || DEFAULT_THRESHOLD_MS) / common.POLL_RATIO;
|
|
58
|
+
|
|
59
|
+
// unref so timer does not block exit
|
|
60
|
+
setInterval(() => poll(enabled, initOptions), pollInterval).unref();
|
|
31
61
|
|
|
32
|
-
const _eventLoopBlockIntegration = ((options = {}) => {
|
|
33
62
|
return {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
63
|
+
start: () => {
|
|
64
|
+
enabled = true;
|
|
65
|
+
},
|
|
66
|
+
stop: () => {
|
|
67
|
+
enabled = false;
|
|
68
|
+
// poll immediately because the timer above might not get a chance to run
|
|
69
|
+
// before the event loop gets blocked
|
|
70
|
+
poll(enabled, initOptions);
|
|
40
71
|
},
|
|
41
72
|
};
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Monitors the Node.js event loop for blocking behavior and reports blocked events to Sentry.
|
|
46
|
-
*
|
|
47
|
-
* Uses a background worker thread to detect when the main thread is blocked for longer than
|
|
48
|
-
* the configured threshold (default: 1 second).
|
|
49
|
-
*
|
|
50
|
-
* When instrumenting via the `--import` flag, this integration will
|
|
51
|
-
* automatically monitor all worker threads as well.
|
|
52
|
-
*
|
|
53
|
-
* ```js
|
|
54
|
-
* // instrument.mjs
|
|
55
|
-
* import * as Sentry from '@sentry/node';
|
|
56
|
-
* import { eventLoopBlockIntegration } from '@sentry/node-native';
|
|
57
|
-
*
|
|
58
|
-
* Sentry.init({
|
|
59
|
-
* dsn: '__YOUR_DSN__',
|
|
60
|
-
* integrations: [
|
|
61
|
-
* eventLoopBlockIntegration({
|
|
62
|
-
* threshold: 500, // Report blocks longer than 500ms
|
|
63
|
-
* }),
|
|
64
|
-
* ],
|
|
65
|
-
* });
|
|
66
|
-
* ```
|
|
67
|
-
*
|
|
68
|
-
* Start your application with:
|
|
69
|
-
* ```bash
|
|
70
|
-
* node --import instrument.mjs app.mjs
|
|
71
|
-
* ```
|
|
72
|
-
*/
|
|
73
|
-
const eventLoopBlockIntegration = core.defineIntegration(_eventLoopBlockIntegration);
|
|
73
|
+
}
|
|
74
74
|
|
|
75
75
|
/**
|
|
76
|
-
* Starts the worker thread
|
|
76
|
+
* Starts the worker thread that will monitor the other threads.
|
|
77
77
|
*
|
|
78
|
-
*
|
|
78
|
+
* This function is only called in the main thread.
|
|
79
79
|
*/
|
|
80
|
-
async function
|
|
80
|
+
async function startWorker(
|
|
81
|
+
dsn,
|
|
81
82
|
client,
|
|
82
83
|
integrationOptions,
|
|
83
84
|
) {
|
|
84
|
-
const dsn = client.getDsn();
|
|
85
|
-
|
|
86
|
-
if (!dsn) {
|
|
87
|
-
return () => {
|
|
88
|
-
//
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
|
|
92
85
|
const contexts = await getContexts(client);
|
|
93
86
|
|
|
94
87
|
// These will not be accurate if sent later from the worker thread
|
|
@@ -103,7 +96,7 @@ async function _startWorker(
|
|
|
103
96
|
}
|
|
104
97
|
|
|
105
98
|
const options = {
|
|
106
|
-
debug: core.
|
|
99
|
+
debug: core.debug.isEnabled(),
|
|
107
100
|
dsn,
|
|
108
101
|
tunnel: initOptions.tunnel,
|
|
109
102
|
environment: initOptions.environment || 'production',
|
|
@@ -117,8 +110,6 @@ async function _startWorker(
|
|
|
117
110
|
contexts,
|
|
118
111
|
};
|
|
119
112
|
|
|
120
|
-
const pollInterval = options.threshold / common.POLL_RATIO;
|
|
121
|
-
|
|
122
113
|
const worker = new node_worker_threads.Worker(new URL('./event-loop-block-watchdog.js', (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('event-loop-block-integration.js', document.baseURI).href))), {
|
|
123
114
|
workerData: options,
|
|
124
115
|
// We don't want any Node args like --import to be passed to the worker
|
|
@@ -131,40 +122,146 @@ async function _startWorker(
|
|
|
131
122
|
worker.terminate();
|
|
132
123
|
});
|
|
133
124
|
|
|
134
|
-
const timer = setInterval(() => {
|
|
135
|
-
try {
|
|
136
|
-
const currentSession = core.getIsolationScope().getSession();
|
|
137
|
-
// We need to copy the session object and remove the toJSON method so it can be sent to the worker
|
|
138
|
-
// serialized without making it a SerializedSession
|
|
139
|
-
const session = currentSession ? { ...currentSession, toJSON: undefined } : undefined;
|
|
140
|
-
// message the worker to tell it the main event loop is still running
|
|
141
|
-
nodeNativeStacktrace.threadPoll({ session, debugImages: core.getFilenameToDebugIdMap(initOptions.stackParser) });
|
|
142
|
-
} catch (_) {
|
|
143
|
-
//
|
|
144
|
-
}
|
|
145
|
-
}, pollInterval);
|
|
146
|
-
// Timer should not block exit
|
|
147
|
-
timer.unref();
|
|
148
|
-
|
|
149
125
|
worker.once('error', (err) => {
|
|
150
|
-
clearInterval(timer);
|
|
151
126
|
log('watchdog worker error', err);
|
|
127
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
128
|
+
worker.terminate();
|
|
152
129
|
});
|
|
153
130
|
|
|
154
131
|
worker.once('exit', (code) => {
|
|
155
|
-
clearInterval(timer);
|
|
156
132
|
log('watchdog worker exit', code);
|
|
157
133
|
});
|
|
158
134
|
|
|
159
135
|
// Ensure this thread can't block app exit
|
|
160
136
|
worker.unref();
|
|
137
|
+
}
|
|
161
138
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
139
|
+
const _eventLoopBlockIntegration = ((options = {}) => {
|
|
140
|
+
let polling;
|
|
141
|
+
|
|
142
|
+
return {
|
|
143
|
+
name: INTEGRATION_NAME,
|
|
144
|
+
async afterAllSetup(client) {
|
|
145
|
+
const dsn = client.getDsn();
|
|
146
|
+
|
|
147
|
+
if (!dsn) {
|
|
148
|
+
log('No DSN configured, skipping starting integration');
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
try {
|
|
153
|
+
polling = await startPolling(client, options);
|
|
154
|
+
|
|
155
|
+
if (node_worker_threads.isMainThread) {
|
|
156
|
+
await startWorker(dsn, client, options);
|
|
157
|
+
}
|
|
158
|
+
} catch (err) {
|
|
159
|
+
log('Failed to start integration', err);
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
start() {
|
|
163
|
+
polling?.start();
|
|
164
|
+
},
|
|
165
|
+
stop() {
|
|
166
|
+
polling?.stop();
|
|
167
|
+
},
|
|
168
|
+
} ;
|
|
169
|
+
}) ;
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Monitors the Node.js event loop for blocking behavior and reports blocked events to Sentry.
|
|
173
|
+
*
|
|
174
|
+
* Uses a background worker thread to detect when the main thread is blocked for longer than
|
|
175
|
+
* the configured threshold (default: 1 second).
|
|
176
|
+
*
|
|
177
|
+
* When instrumenting via the `--import` flag, this integration will
|
|
178
|
+
* automatically monitor all worker threads as well.
|
|
179
|
+
*
|
|
180
|
+
* ```js
|
|
181
|
+
* // instrument.mjs
|
|
182
|
+
* import * as Sentry from '@sentry/node';
|
|
183
|
+
* import { eventLoopBlockIntegration } from '@sentry/node-native';
|
|
184
|
+
*
|
|
185
|
+
* Sentry.init({
|
|
186
|
+
* dsn: '__YOUR_DSN__',
|
|
187
|
+
* integrations: [
|
|
188
|
+
* eventLoopBlockIntegration({
|
|
189
|
+
* threshold: 500, // Report blocks longer than 500ms
|
|
190
|
+
* }),
|
|
191
|
+
* ],
|
|
192
|
+
* });
|
|
193
|
+
* ```
|
|
194
|
+
*
|
|
195
|
+
* Start your application with:
|
|
196
|
+
* ```bash
|
|
197
|
+
* node --import instrument.mjs app.mjs
|
|
198
|
+
* ```
|
|
199
|
+
*/
|
|
200
|
+
const eventLoopBlockIntegration = core.defineIntegration(_eventLoopBlockIntegration);
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Disables Event Loop Block detection for the current thread for the duration
|
|
204
|
+
* of the callback.
|
|
205
|
+
*
|
|
206
|
+
* This utility function allows you to disable block detection during operations that
|
|
207
|
+
* are expected to block the event loop, such as intensive computational tasks or
|
|
208
|
+
* synchronous I/O operations.
|
|
209
|
+
*/
|
|
210
|
+
function disableBlockDetectionForCallback(callback) {
|
|
211
|
+
const integration = core.getClient()?.getIntegrationByName(INTEGRATION_NAME) ;
|
|
212
|
+
|
|
213
|
+
if (!integration) {
|
|
214
|
+
return callback();
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
integration.stop();
|
|
218
|
+
|
|
219
|
+
try {
|
|
220
|
+
const result = callback();
|
|
221
|
+
if (types.isPromise(result)) {
|
|
222
|
+
return result.finally(() => integration.start());
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
integration.start();
|
|
226
|
+
return result;
|
|
227
|
+
} catch (error) {
|
|
228
|
+
integration.start();
|
|
229
|
+
throw error;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Pauses the block detection integration.
|
|
235
|
+
*
|
|
236
|
+
* This function pauses event loop block detection for the current thread.
|
|
237
|
+
*/
|
|
238
|
+
function pauseEventLoopBlockDetection() {
|
|
239
|
+
const integration = core.getClient()?.getIntegrationByName(INTEGRATION_NAME) ;
|
|
240
|
+
|
|
241
|
+
if (!integration) {
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
integration.stop();
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Restarts the block detection integration.
|
|
250
|
+
*
|
|
251
|
+
* This function restarts event loop block detection for the current thread.
|
|
252
|
+
*/
|
|
253
|
+
function restartEventLoopBlockDetection() {
|
|
254
|
+
const integration = core.getClient()?.getIntegrationByName(INTEGRATION_NAME) ;
|
|
255
|
+
|
|
256
|
+
if (!integration) {
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
integration.start();
|
|
167
261
|
}
|
|
168
262
|
|
|
263
|
+
exports.disableBlockDetectionForCallback = disableBlockDetectionForCallback;
|
|
169
264
|
exports.eventLoopBlockIntegration = eventLoopBlockIntegration;
|
|
265
|
+
exports.pauseEventLoopBlockDetection = pauseEventLoopBlockDetection;
|
|
266
|
+
exports.restartEventLoopBlockDetection = restartEventLoopBlockDetection;
|
|
170
267
|
//# sourceMappingURL=event-loop-block-integration.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-loop-block-integration.js","sources":["../../src/event-loop-block-integration.ts"],"sourcesContent":["import { Worker } from 'node:worker_threads';\nimport type { Contexts, Event, EventHint, IntegrationFn } from '@sentry/core';\nimport { defineIntegration, getFilenameToDebugIdMap, getIsolationScope, logger } from '@sentry/core';\nimport type { NodeClient } from '@sentry/node';\nimport { registerThread, threadPoll } from '@sentry-internal/node-native-stacktrace';\nimport type { ThreadBlockedIntegrationOptions, WorkerStartData } from './common';\nimport { POLL_RATIO } from './common';\n\nconst DEFAULT_THRESHOLD_MS = 1_000;\n\nfunction log(message: string, ...args: unknown[]): void {\n logger.log(`[Sentry Block Event Loop] ${message}`, ...args);\n}\n\n/**\n * Gets contexts by calling all event processors. This shouldn't be called until all integrations are setup\n */\nasync function getContexts(client: NodeClient): Promise<Contexts> {\n let event: Event | null = { message: INTEGRATION_NAME };\n const eventHint: EventHint = {};\n\n for (const processor of client.getEventProcessors()) {\n if (event === null) break;\n event = await processor(event, eventHint);\n }\n\n return event?.contexts || {};\n}\n\nconst INTEGRATION_NAME = 'ThreadBlocked';\n\nconst _eventLoopBlockIntegration = ((options: Partial<ThreadBlockedIntegrationOptions> = {}) => {\n return {\n name: INTEGRATION_NAME,\n afterAllSetup(client: NodeClient) {\n registerThread();\n _startWorker(client, options).catch(err => {\n log('Failed to start event loop block worker', err);\n });\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Monitors the Node.js event loop for blocking behavior and reports blocked events to Sentry.\n *\n * Uses a background worker thread to detect when the main thread is blocked for longer than\n * the configured threshold (default: 1 second).\n *\n * When instrumenting via the `--import` flag, this integration will\n * automatically monitor all worker threads as well.\n *\n * ```js\n * // instrument.mjs\n * import * as Sentry from '@sentry/node';\n * import { eventLoopBlockIntegration } from '@sentry/node-native';\n *\n * Sentry.init({\n * dsn: '__YOUR_DSN__',\n * integrations: [\n * eventLoopBlockIntegration({\n * threshold: 500, // Report blocks longer than 500ms\n * }),\n * ],\n * });\n * ```\n *\n * Start your application with:\n * ```bash\n * node --import instrument.mjs app.mjs\n * ```\n */\nexport const eventLoopBlockIntegration = defineIntegration(_eventLoopBlockIntegration);\n\n/**\n * Starts the worker thread\n *\n * @returns A function to stop the worker\n */\nasync function _startWorker(\n client: NodeClient,\n integrationOptions: Partial<ThreadBlockedIntegrationOptions>,\n): Promise<() => void> {\n const dsn = client.getDsn();\n\n if (!dsn) {\n return () => {\n //\n };\n }\n\n const contexts = await getContexts(client);\n\n // These will not be accurate if sent later from the worker thread\n delete contexts.app?.app_memory;\n delete contexts.device?.free_memory;\n\n const initOptions = client.getOptions();\n\n const sdkMetadata = client.getSdkMetadata() || {};\n if (sdkMetadata.sdk) {\n sdkMetadata.sdk.integrations = initOptions.integrations.map(i => i.name);\n }\n\n const options: WorkerStartData = {\n debug: logger.isEnabled(),\n dsn,\n tunnel: initOptions.tunnel,\n environment: initOptions.environment || 'production',\n release: initOptions.release,\n dist: initOptions.dist,\n sdkMetadata,\n appRootPath: integrationOptions.appRootPath,\n threshold: integrationOptions.threshold || DEFAULT_THRESHOLD_MS,\n maxEventsPerHour: integrationOptions.maxEventsPerHour || 1,\n staticTags: integrationOptions.staticTags || {},\n contexts,\n };\n\n const pollInterval = options.threshold / POLL_RATIO;\n\n const worker = new Worker(new URL('./event-loop-block-watchdog.js', import.meta.url), {\n workerData: options,\n // We don't want any Node args like --import to be passed to the worker\n execArgv: [],\n env: { ...process.env, NODE_OPTIONS: undefined },\n });\n\n process.on('exit', () => {\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n worker.terminate();\n });\n\n const timer = setInterval(() => {\n try {\n const currentSession = getIsolationScope().getSession();\n // We need to copy the session object and remove the toJSON method so it can be sent to the worker\n // serialized without making it a SerializedSession\n const session = currentSession ? { ...currentSession, toJSON: undefined } : undefined;\n // message the worker to tell it the main event loop is still running\n threadPoll({ session, debugImages: getFilenameToDebugIdMap(initOptions.stackParser) });\n } catch (_) {\n //\n }\n }, pollInterval);\n // Timer should not block exit\n timer.unref();\n\n worker.once('error', (err: Error) => {\n clearInterval(timer);\n log('watchdog worker error', err);\n });\n\n worker.once('exit', (code: number) => {\n clearInterval(timer);\n log('watchdog worker exit', code);\n });\n\n // Ensure this thread can't block app exit\n worker.unref();\n\n return () => {\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n worker.terminate();\n clearInterval(timer);\n };\n}\n"],"names":["logger","registerThread","defineIntegration","POLL_RATIO","Worker","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ACA,IAAA,MAAA,CAAA,SAAA,EAAA;AACA,IAAA,aAAA,CAAA,KAAA,CAAA;AACA,GAAA;AACA;;;;"}
|
|
1
|
+
{"version":3,"file":"event-loop-block-integration.js","sources":["../../src/event-loop-block-integration.ts"],"sourcesContent":["import { isPromise } from 'node:util/types';\nimport { isMainThread, Worker } from 'node:worker_threads';\nimport type {\n Client,\n ClientOptions,\n Contexts,\n DsnComponents,\n Event,\n EventHint,\n Integration,\n IntegrationFn,\n} from '@sentry/core';\nimport { debug, defineIntegration, getClient, getFilenameToDebugIdMap, getIsolationScope } from '@sentry/core';\nimport type { NodeClient } from '@sentry/node';\nimport { registerThread, threadPoll } from '@sentry-internal/node-native-stacktrace';\nimport type { ThreadBlockedIntegrationOptions, WorkerStartData } from './common';\nimport { POLL_RATIO } from './common';\n\nconst INTEGRATION_NAME = 'ThreadBlocked';\nconst DEFAULT_THRESHOLD_MS = 1_000;\n\nfunction log(message: string, ...args: unknown[]): void {\n debug.log(`[Sentry Event Loop Blocked] ${message}`, ...args);\n}\n\n/**\n * Gets contexts by calling all event processors. This shouldn't be called until all integrations are setup\n */\nasync function getContexts(client: NodeClient): Promise<Contexts> {\n let event: Event | null = { message: INTEGRATION_NAME };\n const eventHint: EventHint = {};\n\n for (const processor of client.getEventProcessors()) {\n if (event === null) break;\n event = await processor(event, eventHint);\n }\n\n return event?.contexts || {};\n}\n\ntype IntegrationInternal = { start: () => void; stop: () => void };\n\nfunction poll(enabled: boolean, clientOptions: ClientOptions): void {\n try {\n const currentSession = getIsolationScope().getSession();\n // We need to copy the session object and remove the toJSON method so it can be sent to the worker\n // serialized without making it a SerializedSession\n const session = currentSession ? { ...currentSession, toJSON: undefined } : undefined;\n // message the worker to tell it the main event loop is still running\n threadPoll({ session, debugImages: getFilenameToDebugIdMap(clientOptions.stackParser) }, !enabled);\n } catch {\n // we ignore all errors\n }\n}\n\n/**\n * Starts polling\n */\nfunction startPolling(\n client: Client,\n integrationOptions: Partial<ThreadBlockedIntegrationOptions>,\n): IntegrationInternal | undefined {\n registerThread();\n\n let enabled = true;\n\n const initOptions = client.getOptions();\n const pollInterval = (integrationOptions.threshold || DEFAULT_THRESHOLD_MS) / POLL_RATIO;\n\n // unref so timer does not block exit\n setInterval(() => poll(enabled, initOptions), pollInterval).unref();\n\n return {\n start: () => {\n enabled = true;\n },\n stop: () => {\n enabled = false;\n // poll immediately because the timer above might not get a chance to run\n // before the event loop gets blocked\n poll(enabled, initOptions);\n },\n };\n}\n\n/**\n * Starts the worker thread that will monitor the other threads.\n *\n * This function is only called in the main thread.\n */\nasync function startWorker(\n dsn: DsnComponents,\n client: NodeClient,\n integrationOptions: Partial<ThreadBlockedIntegrationOptions>,\n): Promise<void> {\n const contexts = await getContexts(client);\n\n // These will not be accurate if sent later from the worker thread\n delete contexts.app?.app_memory;\n delete contexts.device?.free_memory;\n\n const initOptions = client.getOptions();\n\n const sdkMetadata = client.getSdkMetadata() || {};\n if (sdkMetadata.sdk) {\n sdkMetadata.sdk.integrations = initOptions.integrations.map(i => i.name);\n }\n\n const options: WorkerStartData = {\n debug: debug.isEnabled(),\n dsn,\n tunnel: initOptions.tunnel,\n environment: initOptions.environment || 'production',\n release: initOptions.release,\n dist: initOptions.dist,\n sdkMetadata,\n appRootPath: integrationOptions.appRootPath,\n threshold: integrationOptions.threshold || DEFAULT_THRESHOLD_MS,\n maxEventsPerHour: integrationOptions.maxEventsPerHour || 1,\n staticTags: integrationOptions.staticTags || {},\n contexts,\n };\n\n const worker = new Worker(new URL('./event-loop-block-watchdog.js', import.meta.url), {\n workerData: options,\n // We don't want any Node args like --import to be passed to the worker\n execArgv: [],\n env: { ...process.env, NODE_OPTIONS: undefined },\n });\n\n process.on('exit', () => {\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n worker.terminate();\n });\n\n worker.once('error', (err: Error) => {\n log('watchdog worker error', err);\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n worker.terminate();\n });\n\n worker.once('exit', (code: number) => {\n log('watchdog worker exit', code);\n });\n\n // Ensure this thread can't block app exit\n worker.unref();\n}\n\nconst _eventLoopBlockIntegration = ((options: Partial<ThreadBlockedIntegrationOptions> = {}) => {\n let polling: IntegrationInternal | undefined;\n\n return {\n name: INTEGRATION_NAME,\n async afterAllSetup(client: NodeClient): Promise<void> {\n const dsn = client.getDsn();\n\n if (!dsn) {\n log('No DSN configured, skipping starting integration');\n return;\n }\n\n try {\n polling = await startPolling(client, options);\n\n if (isMainThread) {\n await startWorker(dsn, client, options);\n }\n } catch (err) {\n log('Failed to start integration', err);\n }\n },\n start() {\n polling?.start();\n },\n stop() {\n polling?.stop();\n },\n } as Integration & IntegrationInternal;\n}) satisfies IntegrationFn;\n\n/**\n * Monitors the Node.js event loop for blocking behavior and reports blocked events to Sentry.\n *\n * Uses a background worker thread to detect when the main thread is blocked for longer than\n * the configured threshold (default: 1 second).\n *\n * When instrumenting via the `--import` flag, this integration will\n * automatically monitor all worker threads as well.\n *\n * ```js\n * // instrument.mjs\n * import * as Sentry from '@sentry/node';\n * import { eventLoopBlockIntegration } from '@sentry/node-native';\n *\n * Sentry.init({\n * dsn: '__YOUR_DSN__',\n * integrations: [\n * eventLoopBlockIntegration({\n * threshold: 500, // Report blocks longer than 500ms\n * }),\n * ],\n * });\n * ```\n *\n * Start your application with:\n * ```bash\n * node --import instrument.mjs app.mjs\n * ```\n */\nexport const eventLoopBlockIntegration = defineIntegration(_eventLoopBlockIntegration);\n\nexport function disableBlockDetectionForCallback<T>(callback: () => T): T;\nexport function disableBlockDetectionForCallback<T>(callback: () => Promise<T>): Promise<T>;\n/**\n * Disables Event Loop Block detection for the current thread for the duration\n * of the callback.\n *\n * This utility function allows you to disable block detection during operations that\n * are expected to block the event loop, such as intensive computational tasks or\n * synchronous I/O operations.\n */\nexport function disableBlockDetectionForCallback<T>(callback: () => T | Promise<T>): T | Promise<T> {\n const integration = getClient()?.getIntegrationByName(INTEGRATION_NAME) as IntegrationInternal | undefined;\n\n if (!integration) {\n return callback();\n }\n\n integration.stop();\n\n try {\n const result = callback();\n if (isPromise(result)) {\n return result.finally(() => integration.start());\n }\n\n integration.start();\n return result;\n } catch (error) {\n integration.start();\n throw error;\n }\n}\n\n/**\n * Pauses the block detection integration.\n *\n * This function pauses event loop block detection for the current thread.\n */\nexport function pauseEventLoopBlockDetection(): void {\n const integration = getClient()?.getIntegrationByName(INTEGRATION_NAME) as IntegrationInternal | undefined;\n\n if (!integration) {\n return;\n }\n\n integration.stop();\n}\n\n/**\n * Restarts the block detection integration.\n *\n * This function restarts event loop block detection for the current thread.\n */\nexport function restartEventLoopBlockDetection(): void {\n const integration = getClient()?.getIntegrationByName(INTEGRATION_NAME) as IntegrationInternal | undefined;\n\n if (!integration) {\n return;\n }\n\n integration.start();\n}\n"],"names":["debug","getIsolationScope","threadPoll","getFilenameToDebugIdMap","registerThread","POLL_RATIO","Worker","isMainThread","defineIntegration","getClient","isPromise"],"mappings":";;;;;;;;;AAkBA,MAAM,gBAAA,GAAmB,eAAe;AACxC,MAAM,oBAAA,GAAuB,IAAK;;AAElC,SAAS,GAAG,CAAC,OAAO,EAAU,GAAG,IAAI,EAAmB;AACxD,EAAEA,UAAK,CAAC,GAAG,CAAC,CAAC,4BAA4B,EAAE,OAAO,CAAC,CAAA,EAAA,GAAA,IAAA,CAAA;AACA;;AAEA;AACA;AACA;AACA,eAAA,WAAA,CAAA,MAAA,EAAA;AACA,EAAA,IAAA,KAAA,GAAA,EAAA,OAAA,EAAA,gBAAA,EAAA;AACA,EAAA,MAAA,SAAA,GAAA,EAAA;;AAEA,EAAA,KAAA,MAAA,SAAA,IAAA,MAAA,CAAA,kBAAA,EAAA,EAAA;AACA,IAAA,IAAA,KAAA,KAAA,IAAA,EAAA;AACA,IAAA,KAAA,GAAA,MAAA,SAAA,CAAA,KAAA,EAAA,SAAA,CAAA;AACA;;AAEA,EAAA,OAAA,KAAA,EAAA,QAAA,IAAA,EAAA;AACA;;AAIA,SAAA,IAAA,CAAA,OAAA,EAAA,aAAA,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A,yBAAA,GAAAC,sBAAA,CAAA,0BAAA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAA,gCAAA,CAAA,QAAA,EAAA;AACA,EAAA,MAAA,WAAA,GAAAC,cAAA,EAAA,EAAA,oBAAA,CAAA,gBAAA,CAAA;;AAEA,EAAA,IAAA,CAAA,WAAA,EAAA;AACA,IAAA,OAAA,QAAA,EAAA;AACA;;AAEA,EAAA,WAAA,CAAA,IAAA,EAAA;;AAEA,EAAA,IAAA;AACA,IAAA,MAAA,MAAA,GAAA,QAAA,EAAA;AACA,IAAA,IAAAC,eAAA,CAAA,MAAA,CAAA,EAAA;AACA,MAAA,OAAA,MAAA,CAAA,OAAA,CAAA,MAAA,WAAA,CAAA,KAAA,EAAA,CAAA;AACA;;AAEA,IAAA,WAAA,CAAA,KAAA,EAAA;AACA,IAAA,OAAA,MAAA;AACA,GAAA,CAAA,OAAA,KAAA,EAAA;AACA,IAAA,WAAA,CAAA,KAAA,EAAA;AACA,IAAA,MAAA,KAAA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,SAAA,4BAAA,GAAA;AACA,EAAA,MAAA,WAAA,GAAAD,cAAA,EAAA,EAAA,oBAAA,CAAA,gBAAA,CAAA;;AAEA,EAAA,IAAA,CAAA,WAAA,EAAA;AACA,IAAA;AACA;;AAEA,EAAA,WAAA,CAAA,IAAA,EAAA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,SAAA,8BAAA,GAAA;AACA,EAAA,MAAA,WAAA,GAAAA,cAAA,EAAA,EAAA,oBAAA,CAAA,gBAAA,CAAA;;AAEA,EAAA,IAAA,CAAA,WAAA,EAAA;AACA,IAAA;AACA;;AAEA,EAAA,WAAA,CAAA,KAAA,EAAA;AACA;;;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-loop-block-watchdog.js","sources":["../../src/event-loop-block-watchdog.ts"],"sourcesContent":["import { workerData } from 'node:worker_threads';\nimport type { DebugImage, Event, Session, StackFrame, Thread } from '@sentry/core';\nimport {\n createEventEnvelope,\n createSessionEnvelope,\n filenameIsInApp,\n getEnvelopeEndpointWithUrlEncodedAuth,\n makeSession,\n normalizeUrlToBase,\n stripSentryFramesAndReverse,\n updateSession,\n uuid4,\n} from '@sentry/core';\nimport { makeNodeTransport } from '@sentry/node';\nimport { captureStackTrace, getThreadsLastSeen } from '@sentry-internal/node-native-stacktrace';\nimport type { ThreadState, WorkerStartData } from './common';\nimport { POLL_RATIO } from './common';\n\nconst {\n threshold,\n appRootPath,\n contexts,\n debug,\n dist,\n dsn,\n environment,\n maxEventsPerHour,\n release,\n sdkMetadata,\n staticTags: tags,\n tunnel,\n} = workerData as WorkerStartData;\n\nconst pollInterval = threshold / POLL_RATIO;\nconst triggeredThreads = new Set<string>();\n\nfunction log(...msg: unknown[]): void {\n if (debug) {\n // eslint-disable-next-line no-console\n console.log('[Sentry Block Event Loop Watchdog]', ...msg);\n }\n}\n\nfunction createRateLimiter(maxEventsPerHour: number): () => boolean {\n let currentHour = 0;\n let currentCount = 0;\n\n return function isRateLimited(): boolean {\n const hour = new Date().getHours();\n\n if (hour !== currentHour) {\n currentHour = hour;\n currentCount = 0;\n }\n\n if (currentCount >= maxEventsPerHour) {\n if (currentCount === maxEventsPerHour) {\n currentCount += 1;\n log(`Rate limit reached: ${currentCount} events in this hour`);\n }\n return true;\n }\n\n currentCount += 1;\n return false;\n };\n}\n\nconst url = getEnvelopeEndpointWithUrlEncodedAuth(dsn, tunnel, sdkMetadata.sdk);\nconst transport = makeNodeTransport({\n url,\n recordDroppedEvent: () => {\n //\n },\n});\nconst isRateLimited = createRateLimiter(maxEventsPerHour);\n\nasync function sendAbnormalSession(serializedSession: Session | undefined): Promise<void> {\n if (!serializedSession) {\n return;\n }\n\n log('Sending abnormal session');\n const session = makeSession(serializedSession);\n\n updateSession(session, {\n status: 'abnormal',\n abnormal_mechanism: 'anr_foreground',\n release,\n environment,\n });\n\n const envelope = createSessionEnvelope(session, dsn, sdkMetadata, tunnel);\n // Log the envelope so to aid in testing\n log(JSON.stringify(envelope));\n\n await transport.send(envelope);\n}\n\nlog('Started');\n\nfunction prepareStackFrames(stackFrames: StackFrame[] | undefined): StackFrame[] | undefined {\n if (!stackFrames) {\n return undefined;\n }\n\n // Strip Sentry frames and reverse the stack frames so they are in the correct order\n const strippedFrames = stripSentryFramesAndReverse(stackFrames);\n\n for (const frame of strippedFrames) {\n if (!frame.filename) {\n continue;\n }\n\n frame.in_app = filenameIsInApp(frame.filename);\n\n // If we have an app root path, rewrite the filenames to be relative to the app root\n if (appRootPath) {\n frame.filename = normalizeUrlToBase(frame.filename, appRootPath);\n }\n }\n\n return strippedFrames;\n}\n\nfunction stripFileProtocol(filename: string | undefined): string | undefined {\n if (!filename) {\n return undefined;\n }\n return filename.replace(/^file:\\/\\//, '');\n}\n\n// eslint-disable-next-line complexity\nfunction applyDebugMeta(event: Event, debugImages: Record<string, string>): void {\n if (Object.keys(debugImages).length === 0) {\n return;\n }\n\n const normalisedDebugImages = appRootPath ? {} : debugImages;\n if (appRootPath) {\n for (const [path, debugId] of Object.entries(debugImages)) {\n normalisedDebugImages[normalizeUrlToBase(path, appRootPath)] = debugId;\n }\n }\n\n const filenameToDebugId = new Map<string, string>();\n\n for (const exception of event.exception?.values || []) {\n for (const frame of exception.stacktrace?.frames || []) {\n const filename = stripFileProtocol(frame.abs_path || frame.filename);\n if (filename && normalisedDebugImages[filename]) {\n filenameToDebugId.set(filename, normalisedDebugImages[filename] as string);\n }\n }\n }\n\n for (const thread of event.threads?.values || []) {\n for (const frame of thread.stacktrace?.frames || []) {\n const filename = stripFileProtocol(frame.abs_path || frame.filename);\n if (filename && normalisedDebugImages[filename]) {\n filenameToDebugId.set(filename, normalisedDebugImages[filename] as string);\n }\n }\n }\n\n if (filenameToDebugId.size > 0) {\n const images: DebugImage[] = [];\n for (const [code_file, debug_id] of filenameToDebugId.entries()) {\n images.push({\n type: 'sourcemap',\n code_file,\n debug_id,\n });\n }\n event.debug_meta = { images };\n }\n}\n\nfunction getExceptionAndThreads(\n crashedThreadId: string,\n threads: ReturnType<typeof captureStackTrace<ThreadState>>,\n): Event {\n const crashedThread = threads[crashedThreadId];\n\n return {\n exception: {\n values: [\n {\n type: 'EventLoopBlocked',\n value: `Event Loop Blocked for at least ${threshold} ms`,\n stacktrace: { frames: prepareStackFrames(crashedThread?.frames) },\n // This ensures the UI doesn't say 'Crashed in' for the stack trace\n mechanism: { type: 'ANR' },\n thread_id: crashedThreadId,\n },\n ],\n },\n threads: {\n values: Object.entries(threads).map(([threadId, threadState]) => {\n const crashed = threadId === crashedThreadId;\n\n const thread: Thread = {\n id: threadId,\n name: threadId === '0' ? 'main' : `worker-${threadId}`,\n crashed,\n current: true,\n main: threadId === '0',\n };\n\n if (!crashed) {\n thread.stacktrace = { frames: prepareStackFrames(threadState.frames) };\n }\n\n return thread;\n }),\n },\n };\n}\n\nasync function sendBlockEvent(crashedThreadId: string): Promise<void> {\n if (isRateLimited()) {\n return;\n }\n\n const threads = captureStackTrace<ThreadState>();\n const crashedThread = threads[crashedThreadId];\n\n if (!crashedThread) {\n log(`No thread found with ID '${crashedThreadId}'`);\n return;\n }\n\n try {\n await sendAbnormalSession(crashedThread.state?.session);\n } catch (error) {\n log(`Failed to send abnormal session for thread '${crashedThreadId}':`, error);\n }\n\n log('Sending event');\n\n const event: Event = {\n event_id: uuid4(),\n contexts,\n release,\n environment,\n dist,\n platform: 'node',\n level: 'error',\n tags,\n ...getExceptionAndThreads(crashedThreadId, threads),\n };\n\n const allDebugImages: Record<string, string> = Object.values(threads).reduce((acc, threadState) => {\n return { ...acc, ...threadState.state?.debugImages };\n }, {});\n\n applyDebugMeta(event, allDebugImages);\n\n const envelope = createEventEnvelope(event, dsn, sdkMetadata, tunnel);\n // Log the envelope to aid in testing\n log(JSON.stringify(envelope));\n\n await transport.send(envelope);\n await transport.flush(2000);\n}\n\nsetInterval(async () => {\n for (const [threadId, time] of Object.entries(getThreadsLastSeen())) {\n if (time > threshold) {\n if (triggeredThreads.has(threadId)) {\n continue;\n }\n\n log(`Blocked thread detected '${threadId}' last polled ${time} ms ago.`);\n triggeredThreads.add(threadId);\n\n try {\n await sendBlockEvent(threadId);\n } catch (error) {\n log(`Failed to send event for thread '${threadId}':`, error);\n }\n } else {\n triggeredThreads.delete(threadId);\n }\n }\n}, pollInterval);\n"],"names":["workerData","POLL_RATIO","getEnvelopeEndpointWithUrlEncodedAuth","makeNodeTransport","makeSession","updateSession","createSessionEnvelope","stripSentryFramesAndReverse","filenameIsInApp","normalizeUrlToBase","captureStackTrace","uuid4","createEventEnvelope","getThreadsLastSeen"],"mappings":";;;;;;AAkBA,MAAM;AACN,EAAE,SAAS;AACX,EAAE,WAAW;AACb,EAAE,QAAQ;AACV,EAAE,KAAK;AACP,EAAE,IAAI;AACN,EAAE,GAAG;AACL,EAAE,WAAW;AACb,EAAE,gBAAgB;AAClB,EAAE,OAAO;AACT,EAAE,WAAW;AACb,EAAE,UAAU,EAAE,IAAI;AAClB,EAAE,MAAM;AACR,CAAA,GAAIA,8BAAA;;AAEJ,MAAM,YAAA,GAAe,SAAA,GAAYC,iBAAU;AAC3C,MAAM,gBAAA,GAAmB,IAAI,GAAG,EAAU;;AAE1C,SAAS,GAAG,CAAC,GAAG,GAAG,EAAmB;AACtC,EAAE,IAAI,KAAK,EAAE;AACb;AACA,IAAI,OAAO,CAAC,GAAG,CAAC,oCAAoC,EAAE,GAAG,GAAG,CAAC;AAC7D;AACA;;AAEA,SAAS,iBAAiB,CAAC,gBAAgB,EAAyB;AACpE,EAAE,IAAI,WAAA,GAAc,CAAC;AACrB,EAAE,IAAI,YAAA,GAAe,CAAC;;AAEtB,EAAE,OAAO,SAAS,aAAa,GAAY;AAC3C,IAAI,MAAM,IAAA,GAAO,IAAI,IAAI,EAAE,CAAC,QAAQ,EAAE;;AAEtC,IAAI,IAAI,IAAA,KAAS,WAAW,EAAE;AAC9B,MAAM,WAAA,GAAc,IAAI;AACxB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AAA,IAAA,CAAA,QAAA,CAAA;AACA,EAAA,MAAA,SAAA,CAAA,KAAA,CAAA,IAAA,CAAA;AACA;;AAEA,WAAA,CAAA,YAAA;AACA,EAAA,KAAA,MAAA,CAAA,QAAA,EAAA,IAAA,CAAA,IAAA,MAAA,CAAA,OAAA,CAAAC,uCAAA,EAAA,CAAA,EAAA;AACA,IAAA,IAAA,IAAA,GAAA,SAAA,EAAA;AACA,MAAA,IAAA,gBAAA,CAAA,GAAA,CAAA,QAAA,CAAA,EAAA;AACA,QAAA;AACA;;AAEA,MAAA,GAAA,CAAA,CAAA,yBAAA,EAAA,QAAA,CAAA,cAAA,EAAA,IAAA,CAAA,QAAA,CAAA,CAAA;AACA,MAAA,gBAAA,CAAA,GAAA,CAAA,QAAA,CAAA;;AAEA,MAAA,IAAA;AACA,QAAA,MAAA,cAAA,CAAA,QAAA,CAAA;AACA,OAAA,CAAA,OAAA,KAAA,EAAA;AACA,QAAA,GAAA,CAAA,CAAA,iCAAA,EAAA,QAAA,CAAA,EAAA,CAAA,EAAA,KAAA,CAAA;AACA;AACA,KAAA,MAAA;AACA,MAAA,gBAAA,CAAA,MAAA,CAAA,QAAA,CAAA;AACA;AACA;AACA,CAAA,EAAA,YAAA,CAAA;;"}
|
|
1
|
+
{"version":3,"file":"event-loop-block-watchdog.js","sources":["../../src/event-loop-block-watchdog.ts"],"sourcesContent":["import { workerData } from 'node:worker_threads';\nimport type { DebugImage, Event, Session, StackFrame, Thread } from '@sentry/core';\nimport {\n createEventEnvelope,\n createSessionEnvelope,\n filenameIsInApp,\n getEnvelopeEndpointWithUrlEncodedAuth,\n makeSession,\n normalizeUrlToBase,\n stripSentryFramesAndReverse,\n updateSession,\n uuid4,\n} from '@sentry/core';\nimport { makeNodeTransport } from '@sentry/node';\nimport { captureStackTrace, getThreadsLastSeen } from '@sentry-internal/node-native-stacktrace';\nimport type { ThreadState, WorkerStartData } from './common';\nimport { POLL_RATIO } from './common';\n\nconst {\n threshold,\n appRootPath,\n contexts,\n debug,\n dist,\n dsn,\n environment,\n maxEventsPerHour,\n release,\n sdkMetadata,\n staticTags: tags,\n tunnel,\n} = workerData as WorkerStartData;\n\nconst pollInterval = threshold / POLL_RATIO;\nconst triggeredThreads = new Set<string>();\n\nfunction log(...msg: unknown[]): void {\n if (debug) {\n // eslint-disable-next-line no-console\n console.log('[Sentry Event Loop Blocked Watchdog]', ...msg);\n }\n}\n\nfunction createRateLimiter(maxEventsPerHour: number): () => boolean {\n let currentHour = 0;\n let currentCount = 0;\n\n return function isRateLimited(): boolean {\n const hour = new Date().getHours();\n\n if (hour !== currentHour) {\n currentHour = hour;\n currentCount = 0;\n }\n\n if (currentCount >= maxEventsPerHour) {\n if (currentCount === maxEventsPerHour) {\n currentCount += 1;\n log(`Rate limit reached: ${currentCount} events in this hour`);\n }\n return true;\n }\n\n currentCount += 1;\n return false;\n };\n}\n\nconst url = getEnvelopeEndpointWithUrlEncodedAuth(dsn, tunnel, sdkMetadata.sdk);\nconst transport = makeNodeTransport({\n url,\n recordDroppedEvent: () => {\n //\n },\n});\nconst isRateLimited = createRateLimiter(maxEventsPerHour);\n\nasync function sendAbnormalSession(serializedSession: Session | undefined): Promise<void> {\n if (!serializedSession) {\n return;\n }\n\n log('Sending abnormal session');\n const session = makeSession(serializedSession);\n\n updateSession(session, {\n status: 'abnormal',\n abnormal_mechanism: 'anr_foreground',\n release,\n environment,\n });\n\n const envelope = createSessionEnvelope(session, dsn, sdkMetadata, tunnel);\n // Log the envelope so to aid in testing\n log(JSON.stringify(envelope));\n\n await transport.send(envelope);\n}\n\nlog('Started');\n\nfunction prepareStackFrames(stackFrames: StackFrame[] | undefined): StackFrame[] | undefined {\n if (!stackFrames) {\n return undefined;\n }\n\n // Strip Sentry frames and reverse the stack frames so they are in the correct order\n const strippedFrames = stripSentryFramesAndReverse(stackFrames);\n\n for (const frame of strippedFrames) {\n if (!frame.filename) {\n continue;\n }\n\n frame.in_app = filenameIsInApp(frame.filename);\n\n // If we have an app root path, rewrite the filenames to be relative to the app root\n if (appRootPath) {\n frame.filename = normalizeUrlToBase(frame.filename, appRootPath);\n }\n }\n\n return strippedFrames;\n}\n\nfunction stripFileProtocol(filename: string | undefined): string | undefined {\n if (!filename) {\n return undefined;\n }\n return filename.replace(/^file:\\/\\//, '');\n}\n\n// eslint-disable-next-line complexity\nfunction applyDebugMeta(event: Event, debugImages: Record<string, string>): void {\n if (Object.keys(debugImages).length === 0) {\n return;\n }\n\n const normalisedDebugImages = appRootPath ? {} : debugImages;\n if (appRootPath) {\n for (const [path, debugId] of Object.entries(debugImages)) {\n normalisedDebugImages[normalizeUrlToBase(path, appRootPath)] = debugId;\n }\n }\n\n const filenameToDebugId = new Map<string, string>();\n\n for (const exception of event.exception?.values || []) {\n for (const frame of exception.stacktrace?.frames || []) {\n const filename = stripFileProtocol(frame.abs_path || frame.filename);\n if (filename && normalisedDebugImages[filename]) {\n filenameToDebugId.set(filename, normalisedDebugImages[filename] as string);\n }\n }\n }\n\n for (const thread of event.threads?.values || []) {\n for (const frame of thread.stacktrace?.frames || []) {\n const filename = stripFileProtocol(frame.abs_path || frame.filename);\n if (filename && normalisedDebugImages[filename]) {\n filenameToDebugId.set(filename, normalisedDebugImages[filename] as string);\n }\n }\n }\n\n if (filenameToDebugId.size > 0) {\n const images: DebugImage[] = [];\n for (const [code_file, debug_id] of filenameToDebugId.entries()) {\n images.push({\n type: 'sourcemap',\n code_file,\n debug_id,\n });\n }\n event.debug_meta = { images };\n }\n}\n\nfunction getExceptionAndThreads(\n crashedThreadId: string,\n threads: ReturnType<typeof captureStackTrace<ThreadState>>,\n): Event {\n const crashedThread = threads[crashedThreadId];\n\n return {\n exception: {\n values: [\n {\n type: 'EventLoopBlocked',\n value: `Event Loop Blocked for at least ${threshold} ms`,\n stacktrace: { frames: prepareStackFrames(crashedThread?.frames) },\n // This ensures the UI doesn't say 'Crashed in' for the stack trace\n mechanism: { type: 'ANR' },\n thread_id: crashedThreadId,\n },\n ],\n },\n threads: {\n values: Object.entries(threads).map(([threadId, threadState]) => {\n const crashed = threadId === crashedThreadId;\n\n const thread: Thread = {\n id: threadId,\n name: threadId === '0' ? 'main' : `worker-${threadId}`,\n crashed,\n current: true,\n main: threadId === '0',\n };\n\n if (!crashed) {\n thread.stacktrace = { frames: prepareStackFrames(threadState.frames) };\n }\n\n return thread;\n }),\n },\n };\n}\n\nasync function sendBlockEvent(crashedThreadId: string): Promise<void> {\n if (isRateLimited()) {\n return;\n }\n\n const threads = captureStackTrace<ThreadState>();\n const crashedThread = threads[crashedThreadId];\n\n if (!crashedThread) {\n log(`No thread found with ID '${crashedThreadId}'`);\n return;\n }\n\n try {\n await sendAbnormalSession(crashedThread.state?.session);\n } catch (error) {\n log(`Failed to send abnormal session for thread '${crashedThreadId}':`, error);\n }\n\n log('Sending event');\n\n const event: Event = {\n event_id: uuid4(),\n contexts,\n release,\n environment,\n dist,\n platform: 'node',\n level: 'error',\n tags,\n ...getExceptionAndThreads(crashedThreadId, threads),\n };\n\n const allDebugImages: Record<string, string> = Object.values(threads).reduce((acc, threadState) => {\n return { ...acc, ...threadState.state?.debugImages };\n }, {});\n\n applyDebugMeta(event, allDebugImages);\n\n const envelope = createEventEnvelope(event, dsn, sdkMetadata, tunnel);\n // Log the envelope to aid in testing\n log(JSON.stringify(envelope));\n\n await transport.send(envelope);\n await transport.flush(2000);\n}\n\nsetInterval(async () => {\n for (const [threadId, time] of Object.entries(getThreadsLastSeen())) {\n if (time > threshold) {\n if (triggeredThreads.has(threadId)) {\n continue;\n }\n\n log(`Blocked thread detected '${threadId}' last polled ${time} ms ago.`);\n triggeredThreads.add(threadId);\n\n try {\n await sendBlockEvent(threadId);\n } catch (error) {\n log(`Failed to send event for thread '${threadId}':`, error);\n }\n } else {\n triggeredThreads.delete(threadId);\n }\n }\n}, pollInterval);\n"],"names":["workerData","POLL_RATIO","getEnvelopeEndpointWithUrlEncodedAuth","makeNodeTransport","makeSession","updateSession","createSessionEnvelope","stripSentryFramesAndReverse","filename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A,MAAA,GAAA,CAAA,CAAA,yBAAA,EAAA,QAAA,CAAA,cAAA,EAAA,IAAA,CAAA,QAAA,CAAA,CAAA;AACA,MAAA,gBAAA,CAAA,GAAA,CAAA,QAAA,CAAA;;AAEA,MAAA,IAAA;AACA,QAAA,MAAA,cAAA,CAAA,QAAA,CAAA;AACA,OAAA,CAAA,OAAA,KAAA,EAAA;AACA,QAAA,GAAA,CAAA,CAAA,iCAAA,EAAA,QAAA,CAAA,EAAA,CAAA,EAAA,KAAA,CAAA;AACA;AACA,KAAA,MAAA;AACA,MAAA,gBAAA,CAAA,MAAA,CAAA,QAAA,CAAA;AACA;AACA;AACA,CAAA,EAAA,YAAA,CAAA;;"}
|
package/build/cjs/index.js
CHANGED
|
@@ -4,5 +4,8 @@ const eventLoopBlockIntegration = require('./event-loop-block-integration.js');
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
+
exports.disableBlockDetectionForCallback = eventLoopBlockIntegration.disableBlockDetectionForCallback;
|
|
7
8
|
exports.eventLoopBlockIntegration = eventLoopBlockIntegration.eventLoopBlockIntegration;
|
|
9
|
+
exports.pauseEventLoopBlockDetection = eventLoopBlockIntegration.pauseEventLoopBlockDetection;
|
|
10
|
+
exports.restartEventLoopBlockDetection = eventLoopBlockIntegration.restartEventLoopBlockDetection;
|
|
8
11
|
//# sourceMappingURL=index.js.map
|
package/build/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;"}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { isPromise } from 'node:util/types';
|
|
2
|
+
import { isMainThread, Worker } from 'node:worker_threads';
|
|
3
|
+
import { defineIntegration, debug, getIsolationScope, getFilenameToDebugIdMap, getClient } from '@sentry/core';
|
|
3
4
|
import { registerThread, threadPoll } from '@sentry-internal/node-native-stacktrace';
|
|
4
5
|
import { POLL_RATIO } from './common.js';
|
|
5
6
|
|
|
7
|
+
const INTEGRATION_NAME = 'ThreadBlocked';
|
|
6
8
|
const DEFAULT_THRESHOLD_MS = 1000;
|
|
7
9
|
|
|
8
10
|
function log(message, ...args) {
|
|
9
|
-
|
|
11
|
+
debug.log(`[Sentry Event Loop Blocked] ${message}`, ...args);
|
|
10
12
|
}
|
|
11
13
|
|
|
12
14
|
/**
|
|
@@ -24,68 +26,59 @@ async function getContexts(client) {
|
|
|
24
26
|
return event?.contexts || {};
|
|
25
27
|
}
|
|
26
28
|
|
|
27
|
-
|
|
29
|
+
function poll(enabled, clientOptions) {
|
|
30
|
+
try {
|
|
31
|
+
const currentSession = getIsolationScope().getSession();
|
|
32
|
+
// We need to copy the session object and remove the toJSON method so it can be sent to the worker
|
|
33
|
+
// serialized without making it a SerializedSession
|
|
34
|
+
const session = currentSession ? { ...currentSession, toJSON: undefined } : undefined;
|
|
35
|
+
// message the worker to tell it the main event loop is still running
|
|
36
|
+
threadPoll({ session, debugImages: getFilenameToDebugIdMap(clientOptions.stackParser) }, !enabled);
|
|
37
|
+
} catch {
|
|
38
|
+
// we ignore all errors
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Starts polling
|
|
44
|
+
*/
|
|
45
|
+
function startPolling(
|
|
46
|
+
client,
|
|
47
|
+
integrationOptions,
|
|
48
|
+
) {
|
|
49
|
+
registerThread();
|
|
50
|
+
|
|
51
|
+
let enabled = true;
|
|
52
|
+
|
|
53
|
+
const initOptions = client.getOptions();
|
|
54
|
+
const pollInterval = (integrationOptions.threshold || DEFAULT_THRESHOLD_MS) / POLL_RATIO;
|
|
55
|
+
|
|
56
|
+
// unref so timer does not block exit
|
|
57
|
+
setInterval(() => poll(enabled, initOptions), pollInterval).unref();
|
|
28
58
|
|
|
29
|
-
const _eventLoopBlockIntegration = ((options = {}) => {
|
|
30
59
|
return {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
60
|
+
start: () => {
|
|
61
|
+
enabled = true;
|
|
62
|
+
},
|
|
63
|
+
stop: () => {
|
|
64
|
+
enabled = false;
|
|
65
|
+
// poll immediately because the timer above might not get a chance to run
|
|
66
|
+
// before the event loop gets blocked
|
|
67
|
+
poll(enabled, initOptions);
|
|
37
68
|
},
|
|
38
69
|
};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Monitors the Node.js event loop for blocking behavior and reports blocked events to Sentry.
|
|
43
|
-
*
|
|
44
|
-
* Uses a background worker thread to detect when the main thread is blocked for longer than
|
|
45
|
-
* the configured threshold (default: 1 second).
|
|
46
|
-
*
|
|
47
|
-
* When instrumenting via the `--import` flag, this integration will
|
|
48
|
-
* automatically monitor all worker threads as well.
|
|
49
|
-
*
|
|
50
|
-
* ```js
|
|
51
|
-
* // instrument.mjs
|
|
52
|
-
* import * as Sentry from '@sentry/node';
|
|
53
|
-
* import { eventLoopBlockIntegration } from '@sentry/node-native';
|
|
54
|
-
*
|
|
55
|
-
* Sentry.init({
|
|
56
|
-
* dsn: '__YOUR_DSN__',
|
|
57
|
-
* integrations: [
|
|
58
|
-
* eventLoopBlockIntegration({
|
|
59
|
-
* threshold: 500, // Report blocks longer than 500ms
|
|
60
|
-
* }),
|
|
61
|
-
* ],
|
|
62
|
-
* });
|
|
63
|
-
* ```
|
|
64
|
-
*
|
|
65
|
-
* Start your application with:
|
|
66
|
-
* ```bash
|
|
67
|
-
* node --import instrument.mjs app.mjs
|
|
68
|
-
* ```
|
|
69
|
-
*/
|
|
70
|
-
const eventLoopBlockIntegration = defineIntegration(_eventLoopBlockIntegration);
|
|
70
|
+
}
|
|
71
71
|
|
|
72
72
|
/**
|
|
73
|
-
* Starts the worker thread
|
|
73
|
+
* Starts the worker thread that will monitor the other threads.
|
|
74
74
|
*
|
|
75
|
-
*
|
|
75
|
+
* This function is only called in the main thread.
|
|
76
76
|
*/
|
|
77
|
-
async function
|
|
77
|
+
async function startWorker(
|
|
78
|
+
dsn,
|
|
78
79
|
client,
|
|
79
80
|
integrationOptions,
|
|
80
81
|
) {
|
|
81
|
-
const dsn = client.getDsn();
|
|
82
|
-
|
|
83
|
-
if (!dsn) {
|
|
84
|
-
return () => {
|
|
85
|
-
//
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
|
|
89
82
|
const contexts = await getContexts(client);
|
|
90
83
|
|
|
91
84
|
// These will not be accurate if sent later from the worker thread
|
|
@@ -100,7 +93,7 @@ async function _startWorker(
|
|
|
100
93
|
}
|
|
101
94
|
|
|
102
95
|
const options = {
|
|
103
|
-
debug:
|
|
96
|
+
debug: debug.isEnabled(),
|
|
104
97
|
dsn,
|
|
105
98
|
tunnel: initOptions.tunnel,
|
|
106
99
|
environment: initOptions.environment || 'production',
|
|
@@ -114,8 +107,6 @@ async function _startWorker(
|
|
|
114
107
|
contexts,
|
|
115
108
|
};
|
|
116
109
|
|
|
117
|
-
const pollInterval = options.threshold / POLL_RATIO;
|
|
118
|
-
|
|
119
110
|
const worker = new Worker(new URL('./event-loop-block-watchdog.js', import.meta.url), {
|
|
120
111
|
workerData: options,
|
|
121
112
|
// We don't want any Node args like --import to be passed to the worker
|
|
@@ -128,40 +119,143 @@ async function _startWorker(
|
|
|
128
119
|
worker.terminate();
|
|
129
120
|
});
|
|
130
121
|
|
|
131
|
-
const timer = setInterval(() => {
|
|
132
|
-
try {
|
|
133
|
-
const currentSession = getIsolationScope().getSession();
|
|
134
|
-
// We need to copy the session object and remove the toJSON method so it can be sent to the worker
|
|
135
|
-
// serialized without making it a SerializedSession
|
|
136
|
-
const session = currentSession ? { ...currentSession, toJSON: undefined } : undefined;
|
|
137
|
-
// message the worker to tell it the main event loop is still running
|
|
138
|
-
threadPoll({ session, debugImages: getFilenameToDebugIdMap(initOptions.stackParser) });
|
|
139
|
-
} catch (_) {
|
|
140
|
-
//
|
|
141
|
-
}
|
|
142
|
-
}, pollInterval);
|
|
143
|
-
// Timer should not block exit
|
|
144
|
-
timer.unref();
|
|
145
|
-
|
|
146
122
|
worker.once('error', (err) => {
|
|
147
|
-
clearInterval(timer);
|
|
148
123
|
log('watchdog worker error', err);
|
|
124
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
125
|
+
worker.terminate();
|
|
149
126
|
});
|
|
150
127
|
|
|
151
128
|
worker.once('exit', (code) => {
|
|
152
|
-
clearInterval(timer);
|
|
153
129
|
log('watchdog worker exit', code);
|
|
154
130
|
});
|
|
155
131
|
|
|
156
132
|
// Ensure this thread can't block app exit
|
|
157
133
|
worker.unref();
|
|
134
|
+
}
|
|
158
135
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
136
|
+
const _eventLoopBlockIntegration = ((options = {}) => {
|
|
137
|
+
let polling;
|
|
138
|
+
|
|
139
|
+
return {
|
|
140
|
+
name: INTEGRATION_NAME,
|
|
141
|
+
async afterAllSetup(client) {
|
|
142
|
+
const dsn = client.getDsn();
|
|
143
|
+
|
|
144
|
+
if (!dsn) {
|
|
145
|
+
log('No DSN configured, skipping starting integration');
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
try {
|
|
150
|
+
polling = await startPolling(client, options);
|
|
151
|
+
|
|
152
|
+
if (isMainThread) {
|
|
153
|
+
await startWorker(dsn, client, options);
|
|
154
|
+
}
|
|
155
|
+
} catch (err) {
|
|
156
|
+
log('Failed to start integration', err);
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
start() {
|
|
160
|
+
polling?.start();
|
|
161
|
+
},
|
|
162
|
+
stop() {
|
|
163
|
+
polling?.stop();
|
|
164
|
+
},
|
|
165
|
+
} ;
|
|
166
|
+
}) ;
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Monitors the Node.js event loop for blocking behavior and reports blocked events to Sentry.
|
|
170
|
+
*
|
|
171
|
+
* Uses a background worker thread to detect when the main thread is blocked for longer than
|
|
172
|
+
* the configured threshold (default: 1 second).
|
|
173
|
+
*
|
|
174
|
+
* When instrumenting via the `--import` flag, this integration will
|
|
175
|
+
* automatically monitor all worker threads as well.
|
|
176
|
+
*
|
|
177
|
+
* ```js
|
|
178
|
+
* // instrument.mjs
|
|
179
|
+
* import * as Sentry from '@sentry/node';
|
|
180
|
+
* import { eventLoopBlockIntegration } from '@sentry/node-native';
|
|
181
|
+
*
|
|
182
|
+
* Sentry.init({
|
|
183
|
+
* dsn: '__YOUR_DSN__',
|
|
184
|
+
* integrations: [
|
|
185
|
+
* eventLoopBlockIntegration({
|
|
186
|
+
* threshold: 500, // Report blocks longer than 500ms
|
|
187
|
+
* }),
|
|
188
|
+
* ],
|
|
189
|
+
* });
|
|
190
|
+
* ```
|
|
191
|
+
*
|
|
192
|
+
* Start your application with:
|
|
193
|
+
* ```bash
|
|
194
|
+
* node --import instrument.mjs app.mjs
|
|
195
|
+
* ```
|
|
196
|
+
*/
|
|
197
|
+
const eventLoopBlockIntegration = defineIntegration(_eventLoopBlockIntegration);
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Disables Event Loop Block detection for the current thread for the duration
|
|
201
|
+
* of the callback.
|
|
202
|
+
*
|
|
203
|
+
* This utility function allows you to disable block detection during operations that
|
|
204
|
+
* are expected to block the event loop, such as intensive computational tasks or
|
|
205
|
+
* synchronous I/O operations.
|
|
206
|
+
*/
|
|
207
|
+
function disableBlockDetectionForCallback(callback) {
|
|
208
|
+
const integration = getClient()?.getIntegrationByName(INTEGRATION_NAME) ;
|
|
209
|
+
|
|
210
|
+
if (!integration) {
|
|
211
|
+
return callback();
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
integration.stop();
|
|
215
|
+
|
|
216
|
+
try {
|
|
217
|
+
const result = callback();
|
|
218
|
+
if (isPromise(result)) {
|
|
219
|
+
return result.finally(() => integration.start());
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
integration.start();
|
|
223
|
+
return result;
|
|
224
|
+
} catch (error) {
|
|
225
|
+
integration.start();
|
|
226
|
+
throw error;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Pauses the block detection integration.
|
|
232
|
+
*
|
|
233
|
+
* This function pauses event loop block detection for the current thread.
|
|
234
|
+
*/
|
|
235
|
+
function pauseEventLoopBlockDetection() {
|
|
236
|
+
const integration = getClient()?.getIntegrationByName(INTEGRATION_NAME) ;
|
|
237
|
+
|
|
238
|
+
if (!integration) {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
integration.stop();
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Restarts the block detection integration.
|
|
247
|
+
*
|
|
248
|
+
* This function restarts event loop block detection for the current thread.
|
|
249
|
+
*/
|
|
250
|
+
function restartEventLoopBlockDetection() {
|
|
251
|
+
const integration = getClient()?.getIntegrationByName(INTEGRATION_NAME) ;
|
|
252
|
+
|
|
253
|
+
if (!integration) {
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
integration.start();
|
|
164
258
|
}
|
|
165
259
|
|
|
166
|
-
export { eventLoopBlockIntegration };
|
|
260
|
+
export { disableBlockDetectionForCallback, eventLoopBlockIntegration, pauseEventLoopBlockDetection, restartEventLoopBlockDetection };
|
|
167
261
|
//# sourceMappingURL=event-loop-block-integration.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-loop-block-integration.js","sources":["../../src/event-loop-block-integration.ts"],"sourcesContent":["import { Worker } from 'node:worker_threads';\nimport type { Contexts, Event, EventHint, IntegrationFn } from '@sentry/core';\nimport { defineIntegration, getFilenameToDebugIdMap, getIsolationScope, logger } from '@sentry/core';\nimport type { NodeClient } from '@sentry/node';\nimport { registerThread, threadPoll } from '@sentry-internal/node-native-stacktrace';\nimport type { ThreadBlockedIntegrationOptions, WorkerStartData } from './common';\nimport { POLL_RATIO } from './common';\n\nconst DEFAULT_THRESHOLD_MS = 1_000;\n\nfunction log(message: string, ...args: unknown[]): void {\n logger.log(`[Sentry Block Event Loop] ${message}`, ...args);\n}\n\n/**\n * Gets contexts by calling all event processors. This shouldn't be called until all integrations are setup\n */\nasync function getContexts(client: NodeClient): Promise<Contexts> {\n let event: Event | null = { message: INTEGRATION_NAME };\n const eventHint: EventHint = {};\n\n for (const processor of client.getEventProcessors()) {\n if (event === null) break;\n event = await processor(event, eventHint);\n }\n\n return event?.contexts || {};\n}\n\nconst INTEGRATION_NAME = 'ThreadBlocked';\n\nconst _eventLoopBlockIntegration = ((options: Partial<ThreadBlockedIntegrationOptions> = {}) => {\n return {\n name: INTEGRATION_NAME,\n afterAllSetup(client: NodeClient) {\n registerThread();\n _startWorker(client, options).catch(err => {\n log('Failed to start event loop block worker', err);\n });\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Monitors the Node.js event loop for blocking behavior and reports blocked events to Sentry.\n *\n * Uses a background worker thread to detect when the main thread is blocked for longer than\n * the configured threshold (default: 1 second).\n *\n * When instrumenting via the `--import` flag, this integration will\n * automatically monitor all worker threads as well.\n *\n * ```js\n * // instrument.mjs\n * import * as Sentry from '@sentry/node';\n * import { eventLoopBlockIntegration } from '@sentry/node-native';\n *\n * Sentry.init({\n * dsn: '__YOUR_DSN__',\n * integrations: [\n * eventLoopBlockIntegration({\n * threshold: 500, // Report blocks longer than 500ms\n * }),\n * ],\n * });\n * ```\n *\n * Start your application with:\n * ```bash\n * node --import instrument.mjs app.mjs\n * ```\n */\nexport const eventLoopBlockIntegration = defineIntegration(_eventLoopBlockIntegration);\n\n/**\n * Starts the worker thread\n *\n * @returns A function to stop the worker\n */\nasync function _startWorker(\n client: NodeClient,\n integrationOptions: Partial<ThreadBlockedIntegrationOptions>,\n): Promise<() => void> {\n const dsn = client.getDsn();\n\n if (!dsn) {\n return () => {\n //\n };\n }\n\n const contexts = await getContexts(client);\n\n // These will not be accurate if sent later from the worker thread\n delete contexts.app?.app_memory;\n delete contexts.device?.free_memory;\n\n const initOptions = client.getOptions();\n\n const sdkMetadata = client.getSdkMetadata() || {};\n if (sdkMetadata.sdk) {\n sdkMetadata.sdk.integrations = initOptions.integrations.map(i => i.name);\n }\n\n const options: WorkerStartData = {\n debug: logger.isEnabled(),\n dsn,\n tunnel: initOptions.tunnel,\n environment: initOptions.environment || 'production',\n release: initOptions.release,\n dist: initOptions.dist,\n sdkMetadata,\n appRootPath: integrationOptions.appRootPath,\n threshold: integrationOptions.threshold || DEFAULT_THRESHOLD_MS,\n maxEventsPerHour: integrationOptions.maxEventsPerHour || 1,\n staticTags: integrationOptions.staticTags || {},\n contexts,\n };\n\n const pollInterval = options.threshold / POLL_RATIO;\n\n const worker = new Worker(new URL('./event-loop-block-watchdog.js', import.meta.url), {\n workerData: options,\n // We don't want any Node args like --import to be passed to the worker\n execArgv: [],\n env: { ...process.env, NODE_OPTIONS: undefined },\n });\n\n process.on('exit', () => {\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n worker.terminate();\n });\n\n const timer = setInterval(() => {\n try {\n const currentSession = getIsolationScope().getSession();\n // We need to copy the session object and remove the toJSON method so it can be sent to the worker\n // serialized without making it a SerializedSession\n const session = currentSession ? { ...currentSession, toJSON: undefined } : undefined;\n // message the worker to tell it the main event loop is still running\n threadPoll({ session, debugImages: getFilenameToDebugIdMap(initOptions.stackParser) });\n } catch (_) {\n //\n }\n }, pollInterval);\n // Timer should not block exit\n timer.unref();\n\n worker.once('error', (err: Error) => {\n clearInterval(timer);\n log('watchdog worker error', err);\n });\n\n worker.once('exit', (code: number) => {\n clearInterval(timer);\n log('watchdog worker exit', code);\n });\n\n // Ensure this thread can't block app exit\n worker.unref();\n\n return () => {\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n worker.terminate();\n clearInterval(timer);\n };\n}\n"],"names":[],"mappings":";;;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AA,aAAA,CAAA,KAAA,CAAA;AACA,GAAA;AACA;;;;"}
|
|
1
|
+
{"version":3,"file":"event-loop-block-integration.js","sources":["../../src/event-loop-block-integration.ts"],"sourcesContent":["import { isPromise } from 'node:util/types';\nimport { isMainThread, Worker } from 'node:worker_threads';\nimport type {\n Client,\n ClientOptions,\n Contexts,\n DsnComponents,\n Event,\n EventHint,\n Integration,\n IntegrationFn,\n} from '@sentry/core';\nimport { debug, defineIntegration, getClient, getFilenameToDebugIdMap, getIsolationScope } from '@sentry/core';\nimport type { NodeClient } from '@sentry/node';\nimport { registerThread, threadPoll } from '@sentry-internal/node-native-stacktrace';\nimport type { ThreadBlockedIntegrationOptions, WorkerStartData } from './common';\nimport { POLL_RATIO } from './common';\n\nconst INTEGRATION_NAME = 'ThreadBlocked';\nconst DEFAULT_THRESHOLD_MS = 1_000;\n\nfunction log(message: string, ...args: unknown[]): void {\n debug.log(`[Sentry Event Loop Blocked] ${message}`, ...args);\n}\n\n/**\n * Gets contexts by calling all event processors. This shouldn't be called until all integrations are setup\n */\nasync function getContexts(client: NodeClient): Promise<Contexts> {\n let event: Event | null = { message: INTEGRATION_NAME };\n const eventHint: EventHint = {};\n\n for (const processor of client.getEventProcessors()) {\n if (event === null) break;\n event = await processor(event, eventHint);\n }\n\n return event?.contexts || {};\n}\n\ntype IntegrationInternal = { start: () => void; stop: () => void };\n\nfunction poll(enabled: boolean, clientOptions: ClientOptions): void {\n try {\n const currentSession = getIsolationScope().getSession();\n // We need to copy the session object and remove the toJSON method so it can be sent to the worker\n // serialized without making it a SerializedSession\n const session = currentSession ? { ...currentSession, toJSON: undefined } : undefined;\n // message the worker to tell it the main event loop is still running\n threadPoll({ session, debugImages: getFilenameToDebugIdMap(clientOptions.stackParser) }, !enabled);\n } catch {\n // we ignore all errors\n }\n}\n\n/**\n * Starts polling\n */\nfunction startPolling(\n client: Client,\n integrationOptions: Partial<ThreadBlockedIntegrationOptions>,\n): IntegrationInternal | undefined {\n registerThread();\n\n let enabled = true;\n\n const initOptions = client.getOptions();\n const pollInterval = (integrationOptions.threshold || DEFAULT_THRESHOLD_MS) / POLL_RATIO;\n\n // unref so timer does not block exit\n setInterval(() => poll(enabled, initOptions), pollInterval).unref();\n\n return {\n start: () => {\n enabled = true;\n },\n stop: () => {\n enabled = false;\n // poll immediately because the timer above might not get a chance to run\n // before the event loop gets blocked\n poll(enabled, initOptions);\n },\n };\n}\n\n/**\n * Starts the worker thread that will monitor the other threads.\n *\n * This function is only called in the main thread.\n */\nasync function startWorker(\n dsn: DsnComponents,\n client: NodeClient,\n integrationOptions: Partial<ThreadBlockedIntegrationOptions>,\n): Promise<void> {\n const contexts = await getContexts(client);\n\n // These will not be accurate if sent later from the worker thread\n delete contexts.app?.app_memory;\n delete contexts.device?.free_memory;\n\n const initOptions = client.getOptions();\n\n const sdkMetadata = client.getSdkMetadata() || {};\n if (sdkMetadata.sdk) {\n sdkMetadata.sdk.integrations = initOptions.integrations.map(i => i.name);\n }\n\n const options: WorkerStartData = {\n debug: debug.isEnabled(),\n dsn,\n tunnel: initOptions.tunnel,\n environment: initOptions.environment || 'production',\n release: initOptions.release,\n dist: initOptions.dist,\n sdkMetadata,\n appRootPath: integrationOptions.appRootPath,\n threshold: integrationOptions.threshold || DEFAULT_THRESHOLD_MS,\n maxEventsPerHour: integrationOptions.maxEventsPerHour || 1,\n staticTags: integrationOptions.staticTags || {},\n contexts,\n };\n\n const worker = new Worker(new URL('./event-loop-block-watchdog.js', import.meta.url), {\n workerData: options,\n // We don't want any Node args like --import to be passed to the worker\n execArgv: [],\n env: { ...process.env, NODE_OPTIONS: undefined },\n });\n\n process.on('exit', () => {\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n worker.terminate();\n });\n\n worker.once('error', (err: Error) => {\n log('watchdog worker error', err);\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n worker.terminate();\n });\n\n worker.once('exit', (code: number) => {\n log('watchdog worker exit', code);\n });\n\n // Ensure this thread can't block app exit\n worker.unref();\n}\n\nconst _eventLoopBlockIntegration = ((options: Partial<ThreadBlockedIntegrationOptions> = {}) => {\n let polling: IntegrationInternal | undefined;\n\n return {\n name: INTEGRATION_NAME,\n async afterAllSetup(client: NodeClient): Promise<void> {\n const dsn = client.getDsn();\n\n if (!dsn) {\n log('No DSN configured, skipping starting integration');\n return;\n }\n\n try {\n polling = await startPolling(client, options);\n\n if (isMainThread) {\n await startWorker(dsn, client, options);\n }\n } catch (err) {\n log('Failed to start integration', err);\n }\n },\n start() {\n polling?.start();\n },\n stop() {\n polling?.stop();\n },\n } as Integration & IntegrationInternal;\n}) satisfies IntegrationFn;\n\n/**\n * Monitors the Node.js event loop for blocking behavior and reports blocked events to Sentry.\n *\n * Uses a background worker thread to detect when the main thread is blocked for longer than\n * the configured threshold (default: 1 second).\n *\n * When instrumenting via the `--import` flag, this integration will\n * automatically monitor all worker threads as well.\n *\n * ```js\n * // instrument.mjs\n * import * as Sentry from '@sentry/node';\n * import { eventLoopBlockIntegration } from '@sentry/node-native';\n *\n * Sentry.init({\n * dsn: '__YOUR_DSN__',\n * integrations: [\n * eventLoopBlockIntegration({\n * threshold: 500, // Report blocks longer than 500ms\n * }),\n * ],\n * });\n * ```\n *\n * Start your application with:\n * ```bash\n * node --import instrument.mjs app.mjs\n * ```\n */\nexport const eventLoopBlockIntegration = defineIntegration(_eventLoopBlockIntegration);\n\nexport function disableBlockDetectionForCallback<T>(callback: () => T): T;\nexport function disableBlockDetectionForCallback<T>(callback: () => Promise<T>): Promise<T>;\n/**\n * Disables Event Loop Block detection for the current thread for the duration\n * of the callback.\n *\n * This utility function allows you to disable block detection during operations that\n * are expected to block the event loop, such as intensive computational tasks or\n * synchronous I/O operations.\n */\nexport function disableBlockDetectionForCallback<T>(callback: () => T | Promise<T>): T | Promise<T> {\n const integration = getClient()?.getIntegrationByName(INTEGRATION_NAME) as IntegrationInternal | undefined;\n\n if (!integration) {\n return callback();\n }\n\n integration.stop();\n\n try {\n const result = callback();\n if (isPromise(result)) {\n return result.finally(() => integration.start());\n }\n\n integration.start();\n return result;\n } catch (error) {\n integration.start();\n throw error;\n }\n}\n\n/**\n * Pauses the block detection integration.\n *\n * This function pauses event loop block detection for the current thread.\n */\nexport function pauseEventLoopBlockDetection(): void {\n const integration = getClient()?.getIntegrationByName(INTEGRATION_NAME) as IntegrationInternal | undefined;\n\n if (!integration) {\n return;\n }\n\n integration.stop();\n}\n\n/**\n * Restarts the block detection integration.\n *\n * This function restarts event loop block detection for the current thread.\n */\nexport function restartEventLoopBlockDetection(): void {\n const integration = getClient()?.getIntegrationByName(INTEGRATION_NAME) as IntegrationInternal | undefined;\n\n if (!integration) {\n return;\n }\n\n integration.start();\n}\n"],"names":[],"mappings":";;;;;;AAkBA,MAAM,gBAAA,GAAmB,eAAe;AACxC,MAAM,oBAAA,GAAuB,IAAK;;AAElC,SAAS,GAAG,CAAC,OAAO,EAAU,GAAG,IAAI,EAAmB;AACxD,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,4BAA4B,EAAE,OAAO,CAAC,CAAA,EAAA,GAAA,IAAA,CAAA;AACA;;AAEA;AACA;AACA;AACA,eAAA,WAAA,CAAA,MAAA,EAAA;AACA,EAAA,IAAA,KAAA,GAAA,EAAA,OAAA,EAAA,gBAAA,EAAA;AACA,EAAA,MAAA,SAAA,GAAA,EAAA;;AAEA,EAAA,KAAA,MAAA,SAAA,IAAA,MAAA,CAAA,kBAAA,EAAA,EAAA;AACA,IAAA,IAAA,KAAA,KAAA,IAAA,EAAA;AACA,IAAA,KAAA,GAAA,MAAA,SAAA,CAAA,KAAA,EAAA,SAAA,CAAA;AACA;;AAEA,EAAA,OAAA,KAAA,EAAA,QAAA,IAAA,EAAA;AACA;;AAIA,SAAA,IAAA,CAAA,OAAA,EAAA,aAAA,EAAA;AACA,EAAA,IAAA;AACA,IAAA,MAAA,cAAA,GAAA,iBAAA,EAAA,CAAA,UAAA,EAAA;AACA;AACA;AACA,IAAA,MAAA,OAAA,GAAA,cAAA,GAA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MAAA,WAAA,GAAA,SAAA,EAAA,EAAA,oBAAA,CAAA,gBAAA,CAAA;;AAEA,EAAA,IAAA,CAAA,WAAA,EAAA;AACA,IAAA,OAAA,QAAA,EAAA;AACA;;AAEA,EAAA,WAAA,CAAA,IAAA,EAAA;;AAEA,EAAA,IAAA;AACA,IAAA,MAAA,MAAA,GAAA,QAAA,EAAA;AACA,IAAA,IAAA,SAAA,CAAA,MAAA,CAAA,EAAA;AACA,MAAA,OAAA,MAAA,CAAA,OAAA,CAAA,MAAA,WAAA,CAAA,KAAA,EAAA,CAAA;AACA;;AAEA,IAAA,WAAA,CAAA,KAAA,EAAA;AACA,IAAA,OAAA,MAAA;AACA,GAAA,CAAA,OAAA,KAAA,EAAA;AACA,IAAA,WAAA,CAAA,KAAA,EAAA;AACA,IAAA,MAAA,KAAA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,SAAA,4BAAA,GAAA;AACA,EAAA,MAAA,WAAA,GAAA,SAAA,EAAA,EAAA,oBAAA,CAAA,gBAAA,CAAA;;AAEA,EAAA,IAAA,CAAA,WAAA,EAAA;AACA,IAAA;AACA;;AAEA,EAAA,WAAA,CAAA,IAAA,EAAA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,SAAA,8BAAA,GAAA;AACA,EAAA,MAAA,WAAA,GAAA,SAAA,EAAA,EAAA,oBAAA,CAAA,gBAAA,CAAA;;AAEA,EAAA,IAAA,CAAA,WAAA,EAAA;AACA,IAAA;AACA;;AAEA,EAAA,WAAA,CAAA,KAAA,EAAA;AACA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-loop-block-watchdog.js","sources":["../../src/event-loop-block-watchdog.ts"],"sourcesContent":["import { workerData } from 'node:worker_threads';\nimport type { DebugImage, Event, Session, StackFrame, Thread } from '@sentry/core';\nimport {\n createEventEnvelope,\n createSessionEnvelope,\n filenameIsInApp,\n getEnvelopeEndpointWithUrlEncodedAuth,\n makeSession,\n normalizeUrlToBase,\n stripSentryFramesAndReverse,\n updateSession,\n uuid4,\n} from '@sentry/core';\nimport { makeNodeTransport } from '@sentry/node';\nimport { captureStackTrace, getThreadsLastSeen } from '@sentry-internal/node-native-stacktrace';\nimport type { ThreadState, WorkerStartData } from './common';\nimport { POLL_RATIO } from './common';\n\nconst {\n threshold,\n appRootPath,\n contexts,\n debug,\n dist,\n dsn,\n environment,\n maxEventsPerHour,\n release,\n sdkMetadata,\n staticTags: tags,\n tunnel,\n} = workerData as WorkerStartData;\n\nconst pollInterval = threshold / POLL_RATIO;\nconst triggeredThreads = new Set<string>();\n\nfunction log(...msg: unknown[]): void {\n if (debug) {\n // eslint-disable-next-line no-console\n console.log('[Sentry Block Event Loop Watchdog]', ...msg);\n }\n}\n\nfunction createRateLimiter(maxEventsPerHour: number): () => boolean {\n let currentHour = 0;\n let currentCount = 0;\n\n return function isRateLimited(): boolean {\n const hour = new Date().getHours();\n\n if (hour !== currentHour) {\n currentHour = hour;\n currentCount = 0;\n }\n\n if (currentCount >= maxEventsPerHour) {\n if (currentCount === maxEventsPerHour) {\n currentCount += 1;\n log(`Rate limit reached: ${currentCount} events in this hour`);\n }\n return true;\n }\n\n currentCount += 1;\n return false;\n };\n}\n\nconst url = getEnvelopeEndpointWithUrlEncodedAuth(dsn, tunnel, sdkMetadata.sdk);\nconst transport = makeNodeTransport({\n url,\n recordDroppedEvent: () => {\n //\n },\n});\nconst isRateLimited = createRateLimiter(maxEventsPerHour);\n\nasync function sendAbnormalSession(serializedSession: Session | undefined): Promise<void> {\n if (!serializedSession) {\n return;\n }\n\n log('Sending abnormal session');\n const session = makeSession(serializedSession);\n\n updateSession(session, {\n status: 'abnormal',\n abnormal_mechanism: 'anr_foreground',\n release,\n environment,\n });\n\n const envelope = createSessionEnvelope(session, dsn, sdkMetadata, tunnel);\n // Log the envelope so to aid in testing\n log(JSON.stringify(envelope));\n\n await transport.send(envelope);\n}\n\nlog('Started');\n\nfunction prepareStackFrames(stackFrames: StackFrame[] | undefined): StackFrame[] | undefined {\n if (!stackFrames) {\n return undefined;\n }\n\n // Strip Sentry frames and reverse the stack frames so they are in the correct order\n const strippedFrames = stripSentryFramesAndReverse(stackFrames);\n\n for (const frame of strippedFrames) {\n if (!frame.filename) {\n continue;\n }\n\n frame.in_app = filenameIsInApp(frame.filename);\n\n // If we have an app root path, rewrite the filenames to be relative to the app root\n if (appRootPath) {\n frame.filename = normalizeUrlToBase(frame.filename, appRootPath);\n }\n }\n\n return strippedFrames;\n}\n\nfunction stripFileProtocol(filename: string | undefined): string | undefined {\n if (!filename) {\n return undefined;\n }\n return filename.replace(/^file:\\/\\//, '');\n}\n\n// eslint-disable-next-line complexity\nfunction applyDebugMeta(event: Event, debugImages: Record<string, string>): void {\n if (Object.keys(debugImages).length === 0) {\n return;\n }\n\n const normalisedDebugImages = appRootPath ? {} : debugImages;\n if (appRootPath) {\n for (const [path, debugId] of Object.entries(debugImages)) {\n normalisedDebugImages[normalizeUrlToBase(path, appRootPath)] = debugId;\n }\n }\n\n const filenameToDebugId = new Map<string, string>();\n\n for (const exception of event.exception?.values || []) {\n for (const frame of exception.stacktrace?.frames || []) {\n const filename = stripFileProtocol(frame.abs_path || frame.filename);\n if (filename && normalisedDebugImages[filename]) {\n filenameToDebugId.set(filename, normalisedDebugImages[filename] as string);\n }\n }\n }\n\n for (const thread of event.threads?.values || []) {\n for (const frame of thread.stacktrace?.frames || []) {\n const filename = stripFileProtocol(frame.abs_path || frame.filename);\n if (filename && normalisedDebugImages[filename]) {\n filenameToDebugId.set(filename, normalisedDebugImages[filename] as string);\n }\n }\n }\n\n if (filenameToDebugId.size > 0) {\n const images: DebugImage[] = [];\n for (const [code_file, debug_id] of filenameToDebugId.entries()) {\n images.push({\n type: 'sourcemap',\n code_file,\n debug_id,\n });\n }\n event.debug_meta = { images };\n }\n}\n\nfunction getExceptionAndThreads(\n crashedThreadId: string,\n threads: ReturnType<typeof captureStackTrace<ThreadState>>,\n): Event {\n const crashedThread = threads[crashedThreadId];\n\n return {\n exception: {\n values: [\n {\n type: 'EventLoopBlocked',\n value: `Event Loop Blocked for at least ${threshold} ms`,\n stacktrace: { frames: prepareStackFrames(crashedThread?.frames) },\n // This ensures the UI doesn't say 'Crashed in' for the stack trace\n mechanism: { type: 'ANR' },\n thread_id: crashedThreadId,\n },\n ],\n },\n threads: {\n values: Object.entries(threads).map(([threadId, threadState]) => {\n const crashed = threadId === crashedThreadId;\n\n const thread: Thread = {\n id: threadId,\n name: threadId === '0' ? 'main' : `worker-${threadId}`,\n crashed,\n current: true,\n main: threadId === '0',\n };\n\n if (!crashed) {\n thread.stacktrace = { frames: prepareStackFrames(threadState.frames) };\n }\n\n return thread;\n }),\n },\n };\n}\n\nasync function sendBlockEvent(crashedThreadId: string): Promise<void> {\n if (isRateLimited()) {\n return;\n }\n\n const threads = captureStackTrace<ThreadState>();\n const crashedThread = threads[crashedThreadId];\n\n if (!crashedThread) {\n log(`No thread found with ID '${crashedThreadId}'`);\n return;\n }\n\n try {\n await sendAbnormalSession(crashedThread.state?.session);\n } catch (error) {\n log(`Failed to send abnormal session for thread '${crashedThreadId}':`, error);\n }\n\n log('Sending event');\n\n const event: Event = {\n event_id: uuid4(),\n contexts,\n release,\n environment,\n dist,\n platform: 'node',\n level: 'error',\n tags,\n ...getExceptionAndThreads(crashedThreadId, threads),\n };\n\n const allDebugImages: Record<string, string> = Object.values(threads).reduce((acc, threadState) => {\n return { ...acc, ...threadState.state?.debugImages };\n }, {});\n\n applyDebugMeta(event, allDebugImages);\n\n const envelope = createEventEnvelope(event, dsn, sdkMetadata, tunnel);\n // Log the envelope to aid in testing\n log(JSON.stringify(envelope));\n\n await transport.send(envelope);\n await transport.flush(2000);\n}\n\nsetInterval(async () => {\n for (const [threadId, time] of Object.entries(getThreadsLastSeen())) {\n if (time > threshold) {\n if (triggeredThreads.has(threadId)) {\n continue;\n }\n\n log(`Blocked thread detected '${threadId}' last polled ${time} ms ago.`);\n triggeredThreads.add(threadId);\n\n try {\n await sendBlockEvent(threadId);\n } catch (error) {\n log(`Failed to send event for thread '${threadId}':`, error);\n }\n } else {\n triggeredThreads.delete(threadId);\n }\n }\n}, pollInterval);\n"],"names":[],"mappings":";;;;;;AAkBA,MAAM;AACN,EAAE,SAAS;AACX,EAAE,WAAW;AACb,EAAE,QAAQ;AACV,EAAE,KAAK;AACP,EAAE,IAAI;AACN,EAAE,GAAG;AACL,EAAE,WAAW;AACb,EAAE,gBAAgB;AAClB,EAAE,OAAO;AACT,EAAE,WAAW;AACb,EAAE,UAAU,EAAE,IAAI;AAClB,EAAE,MAAM;AACR,CAAA,GAAI,UAAA;;AAEJ,MAAM,YAAA,GAAe,SAAA,GAAY,UAAU;AAC3C,MAAM,gBAAA,GAAmB,IAAI,GAAG,EAAU;;AAE1C,SAAS,GAAG,CAAC,GAAG,GAAG,EAAmB;AACtC,EAAE,IAAI,KAAK,EAAE;AACb;AACA,IAAI,OAAO,CAAC,GAAG,CAAC,oCAAoC,EAAE,GAAG,GAAG,CAAC;AAC7D;AACA;;AAEA,SAAS,iBAAiB,CAAC,gBAAgB,EAAyB;AACpE,EAAE,IAAI,WAAA,GAAc,CAAC;AACrB,EAAE,IAAI,YAAA,GAAe,CAAC;;AAEtB,EAAE,OAAO,SAAS,aAAa,GAAY;AAC3C,IAAI,MAAM,IAAA,GAAO,IAAI,IAAI,EAAE,CAAC,QAAQ,EAAE;;AAEtC,IAAI,IAAI,IAAA,KAAS,WAAW,EAAE;AAC9B,MAAM,WAAA,GAAc,IAAI;AACxB,MAAM,YAAA,GAAe,CAAC;AACtB;;AAEA,IAAI,IAAI,YAAA,IAAgB,gBAAgB,EAAE;AAC1C,MAAM,IAAI,YAAA,KAAiB,gBAAgB,EAAE;AAC7C,QAAQ,YAAA,IAAgB,CAAC;AACzB,QAAQ,GAAG,CAAC,CAAC,oBAAoB,EAAE,YAAY,CAAC,oBAAoB,CAAC,CAAC;AACtE;AACA,MAAM,OAAO,IAAI;AACjB;;AAEA,IAAI,YAAA,IAAgB,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,EAAA;AACA,QAAA;AACA;;AAEA,MAAA,GAAA,CAAA,CAAA,yBAAA,EAAA,QAAA,CAAA,cAAA,EAAA,IAAA,CAAA,QAAA,CAAA,CAAA;AACA,MAAA,gBAAA,CAAA,GAAA,CAAA,QAAA,CAAA;;AAEA,MAAA,IAAA;AACA,QAAA,MAAA,cAAA,CAAA,QAAA,CAAA;AACA,OAAA,CAAA,OAAA,KAAA,EAAA;AACA,QAAA,GAAA,CAAA,CAAA,iCAAA,EAAA,QAAA,CAAA,EAAA,CAAA,EAAA,KAAA,CAAA;AACA;AACA,KAAA,MAAA;AACA,MAAA,gBAAA,CAAA,MAAA,CAAA,QAAA,CAAA;AACA;AACA;AACA,CAAA,EAAA,YAAA,CAAA"}
|
|
1
|
+
{"version":3,"file":"event-loop-block-watchdog.js","sources":["../../src/event-loop-block-watchdog.ts"],"sourcesContent":["import { workerData } from 'node:worker_threads';\nimport type { DebugImage, Event, Session, StackFrame, Thread } from '@sentry/core';\nimport {\n createEventEnvelope,\n createSessionEnvelope,\n filenameIsInApp,\n getEnvelopeEndpointWithUrlEncodedAuth,\n makeSession,\n normalizeUrlToBase,\n stripSentryFramesAndReverse,\n updateSession,\n uuid4,\n} from '@sentry/core';\nimport { makeNodeTransport } from '@sentry/node';\nimport { captureStackTrace, getThreadsLastSeen } from '@sentry-internal/node-native-stacktrace';\nimport type { ThreadState, WorkerStartData } from './common';\nimport { POLL_RATIO } from './common';\n\nconst {\n threshold,\n appRootPath,\n contexts,\n debug,\n dist,\n dsn,\n environment,\n maxEventsPerHour,\n release,\n sdkMetadata,\n staticTags: tags,\n tunnel,\n} = workerData as WorkerStartData;\n\nconst pollInterval = threshold / POLL_RATIO;\nconst triggeredThreads = new Set<string>();\n\nfunction log(...msg: unknown[]): void {\n if (debug) {\n // eslint-disable-next-line no-console\n console.log('[Sentry Event Loop Blocked Watchdog]', ...msg);\n }\n}\n\nfunction createRateLimiter(maxEventsPerHour: number): () => boolean {\n let currentHour = 0;\n let currentCount = 0;\n\n return function isRateLimited(): boolean {\n const hour = new Date().getHours();\n\n if (hour !== currentHour) {\n currentHour = hour;\n currentCount = 0;\n }\n\n if (currentCount >= maxEventsPerHour) {\n if (currentCount === maxEventsPerHour) {\n currentCount += 1;\n log(`Rate limit reached: ${currentCount} events in this hour`);\n }\n return true;\n }\n\n currentCount += 1;\n return false;\n };\n}\n\nconst url = getEnvelopeEndpointWithUrlEncodedAuth(dsn, tunnel, sdkMetadata.sdk);\nconst transport = makeNodeTransport({\n url,\n recordDroppedEvent: () => {\n //\n },\n});\nconst isRateLimited = createRateLimiter(maxEventsPerHour);\n\nasync function sendAbnormalSession(serializedSession: Session | undefined): Promise<void> {\n if (!serializedSession) {\n return;\n }\n\n log('Sending abnormal session');\n const session = makeSession(serializedSession);\n\n updateSession(session, {\n status: 'abnormal',\n abnormal_mechanism: 'anr_foreground',\n release,\n environment,\n });\n\n const envelope = createSessionEnvelope(session, dsn, sdkMetadata, tunnel);\n // Log the envelope so to aid in testing\n log(JSON.stringify(envelope));\n\n await transport.send(envelope);\n}\n\nlog('Started');\n\nfunction prepareStackFrames(stackFrames: StackFrame[] | undefined): StackFrame[] | undefined {\n if (!stackFrames) {\n return undefined;\n }\n\n // Strip Sentry frames and reverse the stack frames so they are in the correct order\n const strippedFrames = stripSentryFramesAndReverse(stackFrames);\n\n for (const frame of strippedFrames) {\n if (!frame.filename) {\n continue;\n }\n\n frame.in_app = filenameIsInApp(frame.filename);\n\n // If we have an app root path, rewrite the filenames to be relative to the app root\n if (appRootPath) {\n frame.filename = normalizeUrlToBase(frame.filename, appRootPath);\n }\n }\n\n return strippedFrames;\n}\n\nfunction stripFileProtocol(filename: string | undefined): string | undefined {\n if (!filename) {\n return undefined;\n }\n return filename.replace(/^file:\\/\\//, '');\n}\n\n// eslint-disable-next-line complexity\nfunction applyDebugMeta(event: Event, debugImages: Record<string, string>): void {\n if (Object.keys(debugImages).length === 0) {\n return;\n }\n\n const normalisedDebugImages = appRootPath ? {} : debugImages;\n if (appRootPath) {\n for (const [path, debugId] of Object.entries(debugImages)) {\n normalisedDebugImages[normalizeUrlToBase(path, appRootPath)] = debugId;\n }\n }\n\n const filenameToDebugId = new Map<string, string>();\n\n for (const exception of event.exception?.values || []) {\n for (const frame of exception.stacktrace?.frames || []) {\n const filename = stripFileProtocol(frame.abs_path || frame.filename);\n if (filename && normalisedDebugImages[filename]) {\n filenameToDebugId.set(filename, normalisedDebugImages[filename] as string);\n }\n }\n }\n\n for (const thread of event.threads?.values || []) {\n for (const frame of thread.stacktrace?.frames || []) {\n const filename = stripFileProtocol(frame.abs_path || frame.filename);\n if (filename && normalisedDebugImages[filename]) {\n filenameToDebugId.set(filename, normalisedDebugImages[filename] as string);\n }\n }\n }\n\n if (filenameToDebugId.size > 0) {\n const images: DebugImage[] = [];\n for (const [code_file, debug_id] of filenameToDebugId.entries()) {\n images.push({\n type: 'sourcemap',\n code_file,\n debug_id,\n });\n }\n event.debug_meta = { images };\n }\n}\n\nfunction getExceptionAndThreads(\n crashedThreadId: string,\n threads: ReturnType<typeof captureStackTrace<ThreadState>>,\n): Event {\n const crashedThread = threads[crashedThreadId];\n\n return {\n exception: {\n values: [\n {\n type: 'EventLoopBlocked',\n value: `Event Loop Blocked for at least ${threshold} ms`,\n stacktrace: { frames: prepareStackFrames(crashedThread?.frames) },\n // This ensures the UI doesn't say 'Crashed in' for the stack trace\n mechanism: { type: 'ANR' },\n thread_id: crashedThreadId,\n },\n ],\n },\n threads: {\n values: Object.entries(threads).map(([threadId, threadState]) => {\n const crashed = threadId === crashedThreadId;\n\n const thread: Thread = {\n id: threadId,\n name: threadId === '0' ? 'main' : `worker-${threadId}`,\n crashed,\n current: true,\n main: threadId === '0',\n };\n\n if (!crashed) {\n thread.stacktrace = { frames: prepareStackFrames(threadState.frames) };\n }\n\n return thread;\n }),\n },\n };\n}\n\nasync function sendBlockEvent(crashedThreadId: string): Promise<void> {\n if (isRateLimited()) {\n return;\n }\n\n const threads = captureStackTrace<ThreadState>();\n const crashedThread = threads[crashedThreadId];\n\n if (!crashedThread) {\n log(`No thread found with ID '${crashedThreadId}'`);\n return;\n }\n\n try {\n await sendAbnormalSession(crashedThread.state?.session);\n } catch (error) {\n log(`Failed to send abnormal session for thread '${crashedThreadId}':`, error);\n }\n\n log('Sending event');\n\n const event: Event = {\n event_id: uuid4(),\n contexts,\n release,\n environment,\n dist,\n platform: 'node',\n level: 'error',\n tags,\n ...getExceptionAndThreads(crashedThreadId, threads),\n };\n\n const allDebugImages: Record<string, string> = Object.values(threads).reduce((acc, threadState) => {\n return { ...acc, ...threadState.state?.debugImages };\n }, {});\n\n applyDebugMeta(event, allDebugImages);\n\n const envelope = createEventEnvelope(event, dsn, sdkMetadata, tunnel);\n // Log the envelope to aid in testing\n log(JSON.stringify(envelope));\n\n await transport.send(envelope);\n await transport.flush(2000);\n}\n\nsetInterval(async () => {\n for (const [threadId, time] of Object.entries(getThreadsLastSeen())) {\n if (time > threshold) {\n if (triggeredThreads.has(threadId)) {\n continue;\n }\n\n log(`Blocked thread detected '${threadId}' last polled ${time} ms ago.`);\n triggeredThreads.add(threadId);\n\n try {\n await sendBlockEvent(threadId);\n } catch (error) {\n log(`Failed to send event for thread '${threadId}':`, error);\n }\n } else {\n triggeredThreads.delete(threadId);\n }\n }\n}, pollInterval);\n"],"names":[],"mappings":";;;;;;AAkBA,MAAM;AACN,EAAE,SAAS;AACX,EAAE,WAAW;AACb,EAAE,QAAQ;AACV,EAAE,KAAK;AACP,EAAE,IAAI;AACN,EAAE,GAAG;AACL,EAAE,WAAW;AACb,EAAE,gBAAgB;AAClB,EAAE,OAAO;AACT,EAAE,WAAW;AACb,EAAE,UAAU,EAAE,IAAI;AAClB,EAAE,MAAM;AACR,CAAA,GAAI,UAAA;;AAEJ,MAAM,YAAA,GAAe,SAAA,GAAY,UAAU;AAC3C,MAAM,gBAAA,GAAmB,IAAI,GAAG,EAAU;;AAE1C,SAAS,GAAG,CAAC,GAAG,GAAG,EAAmB;AACtC,EAAE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BlockIntegration } from './event-loop-block-integration.js';
|
|
1
|
+
export { disableBlockDetectionForCallback, eventLoopBlockIntegration, pauseEventLoopBlockDetection, restartEventLoopBlockDetection } from './event-loop-block-integration.js';
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/build/esm/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"type":"module","version":"9.
|
|
1
|
+
{"type":"module","version":"9.40.0","sideEffects":false}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Integration } from '@sentry/core';
|
|
1
2
|
import type { ThreadBlockedIntegrationOptions } from './common';
|
|
2
3
|
/**
|
|
3
4
|
* Monitors the Node.js event loop for blocking behavior and reports blocked events to Sentry.
|
|
@@ -28,5 +29,19 @@ import type { ThreadBlockedIntegrationOptions } from './common';
|
|
|
28
29
|
* node --import instrument.mjs app.mjs
|
|
29
30
|
* ```
|
|
30
31
|
*/
|
|
31
|
-
export declare const eventLoopBlockIntegration: (options?: Partial<ThreadBlockedIntegrationOptions> | undefined) =>
|
|
32
|
+
export declare const eventLoopBlockIntegration: (options?: Partial<ThreadBlockedIntegrationOptions> | undefined) => Integration;
|
|
33
|
+
export declare function disableBlockDetectionForCallback<T>(callback: () => T): T;
|
|
34
|
+
export declare function disableBlockDetectionForCallback<T>(callback: () => Promise<T>): Promise<T>;
|
|
35
|
+
/**
|
|
36
|
+
* Pauses the block detection integration.
|
|
37
|
+
*
|
|
38
|
+
* This function pauses event loop block detection for the current thread.
|
|
39
|
+
*/
|
|
40
|
+
export declare function pauseEventLoopBlockDetection(): void;
|
|
41
|
+
/**
|
|
42
|
+
* Restarts the block detection integration.
|
|
43
|
+
*
|
|
44
|
+
* This function restarts event loop block detection for the current thread.
|
|
45
|
+
*/
|
|
46
|
+
export declare function restartEventLoopBlockDetection(): void;
|
|
32
47
|
//# sourceMappingURL=event-loop-block-integration.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-loop-block-integration.d.ts","sourceRoot":"","sources":["../../src/event-loop-block-integration.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"event-loop-block-integration.d.ts","sourceRoot":"","sources":["../../src/event-loop-block-integration.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAOV,WAAW,EAEZ,MAAM,cAAc,CAAC;AAItB,OAAO,KAAK,EAAE,+BAA+B,EAAmB,MAAM,UAAU,CAAC;AAsKjF;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,yBAAyB,iFAAgD,CAAC;AAEvF,wBAAgB,gCAAgC,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;AAC1E,wBAAgB,gCAAgC,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAgC5F;;;;GAIG;AACH,wBAAgB,4BAA4B,IAAI,IAAI,CAQnD;AAED;;;;GAIG;AACH,wBAAgB,8BAA8B,IAAI,IAAI,CAQrD"}
|
package/build/types/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { eventLoopBlockIntegration } from './event-loop-block-integration';
|
|
1
|
+
export { eventLoopBlockIntegration, disableBlockDetectionForCallback, pauseEventLoopBlockDetection, restartEventLoopBlockDetection, } from './event-loop-block-integration';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,gCAAgC,EAChC,4BAA4B,EAC5B,8BAA8B,GAC/B,MAAM,gCAAgC,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Integration } from '@sentry/core';
|
|
1
2
|
import { ThreadBlockedIntegrationOptions } from './common';
|
|
2
3
|
/**
|
|
3
4
|
* Monitors the Node.js event loop for blocking behavior and reports blocked events to Sentry.
|
|
@@ -28,5 +29,19 @@ import { ThreadBlockedIntegrationOptions } from './common';
|
|
|
28
29
|
* node --import instrument.mjs app.mjs
|
|
29
30
|
* ```
|
|
30
31
|
*/
|
|
31
|
-
export declare const eventLoopBlockIntegration: (options?: Partial<ThreadBlockedIntegrationOptions> | undefined) =>
|
|
32
|
+
export declare const eventLoopBlockIntegration: (options?: Partial<ThreadBlockedIntegrationOptions> | undefined) => Integration;
|
|
33
|
+
export declare function disableBlockDetectionForCallback<T>(callback: () => T): T;
|
|
34
|
+
export declare function disableBlockDetectionForCallback<T>(callback: () => Promise<T>): Promise<T>;
|
|
35
|
+
/**
|
|
36
|
+
* Pauses the block detection integration.
|
|
37
|
+
*
|
|
38
|
+
* This function pauses event loop block detection for the current thread.
|
|
39
|
+
*/
|
|
40
|
+
export declare function pauseEventLoopBlockDetection(): void;
|
|
41
|
+
/**
|
|
42
|
+
* Restarts the block detection integration.
|
|
43
|
+
*
|
|
44
|
+
* This function restarts event loop block detection for the current thread.
|
|
45
|
+
*/
|
|
46
|
+
export declare function restartEventLoopBlockDetection(): void;
|
|
32
47
|
//# sourceMappingURL=event-loop-block-integration.d.ts.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { eventLoopBlockIntegration } from './event-loop-block-integration';
|
|
1
|
+
export { eventLoopBlockIntegration, disableBlockDetectionForCallback, pauseEventLoopBlockDetection, restartEventLoopBlockDetection, } from './event-loop-block-integration';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sentry/node-native",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.40.0",
|
|
4
4
|
"description": "Native Tools for the Official Sentry Node.js SDK",
|
|
5
5
|
"repository": "git://github.com/getsentry/sentry-javascript.git",
|
|
6
6
|
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/node-native",
|
|
@@ -63,9 +63,9 @@
|
|
|
63
63
|
"build:tarball": "npm pack"
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
|
-
"@sentry-internal/node-native-stacktrace": "^0.
|
|
67
|
-
"@sentry/core": "9.
|
|
68
|
-
"@sentry/node": "9.
|
|
66
|
+
"@sentry-internal/node-native-stacktrace": "^0.2.0",
|
|
67
|
+
"@sentry/core": "9.40.0",
|
|
68
|
+
"@sentry/node": "9.40.0"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
71
|
"@types/node": "^18.19.1"
|