@sentry/node-native 9.38.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.
Files changed (32) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +68 -0
  3. package/build/cjs/common.js +6 -0
  4. package/build/cjs/common.js.map +1 -0
  5. package/build/cjs/event-loop-block-integration.js +170 -0
  6. package/build/cjs/event-loop-block-integration.js.map +1 -0
  7. package/build/cjs/event-loop-block-watchdog.js +275 -0
  8. package/build/cjs/event-loop-block-watchdog.js.map +1 -0
  9. package/build/cjs/index.js +8 -0
  10. package/build/cjs/index.js.map +1 -0
  11. package/build/esm/common.js +4 -0
  12. package/build/esm/common.js.map +1 -0
  13. package/build/esm/event-loop-block-integration.js +167 -0
  14. package/build/esm/event-loop-block-integration.js.map +1 -0
  15. package/build/esm/event-loop-block-watchdog.js +275 -0
  16. package/build/esm/event-loop-block-watchdog.js.map +1 -0
  17. package/build/esm/index.js +2 -0
  18. package/build/esm/index.js.map +1 -0
  19. package/build/esm/package.json +1 -0
  20. package/build/types/common.d.ts +43 -0
  21. package/build/types/common.d.ts.map +1 -0
  22. package/build/types/event-loop-block-integration.d.ts +32 -0
  23. package/build/types/event-loop-block-integration.d.ts.map +1 -0
  24. package/build/types/event-loop-block-watchdog.d.ts +2 -0
  25. package/build/types/event-loop-block-watchdog.d.ts.map +1 -0
  26. package/build/types/index.d.ts +2 -0
  27. package/build/types/index.d.ts.map +1 -0
  28. package/build/types-ts3.8/common.d.ts +43 -0
  29. package/build/types-ts3.8/event-loop-block-integration.d.ts +32 -0
  30. package/build/types-ts3.8/event-loop-block-watchdog.d.ts +2 -0
  31. package/build/types-ts3.8/index.d.ts +2 -0
  32. package/package.json +87 -0
@@ -0,0 +1,167 @@
1
+ import { Worker } from 'node:worker_threads';
2
+ import { defineIntegration, logger, getIsolationScope, getFilenameToDebugIdMap } from '@sentry/core';
3
+ import { registerThread, threadPoll } from '@sentry-internal/node-native-stacktrace';
4
+ import { POLL_RATIO } from './common.js';
5
+
6
+ const DEFAULT_THRESHOLD_MS = 1000;
7
+
8
+ function log(message, ...args) {
9
+ logger.log(`[Sentry Block Event Loop] ${message}`, ...args);
10
+ }
11
+
12
+ /**
13
+ * Gets contexts by calling all event processors. This shouldn't be called until all integrations are setup
14
+ */
15
+ async function getContexts(client) {
16
+ let event = { message: INTEGRATION_NAME };
17
+ const eventHint = {};
18
+
19
+ for (const processor of client.getEventProcessors()) {
20
+ if (event === null) break;
21
+ event = await processor(event, eventHint);
22
+ }
23
+
24
+ return event?.contexts || {};
25
+ }
26
+
27
+ const INTEGRATION_NAME = 'ThreadBlocked';
28
+
29
+ const _eventLoopBlockIntegration = ((options = {}) => {
30
+ return {
31
+ name: INTEGRATION_NAME,
32
+ afterAllSetup(client) {
33
+ registerThread();
34
+ _startWorker(client, options).catch(err => {
35
+ log('Failed to start event loop block worker', err);
36
+ });
37
+ },
38
+ };
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);
71
+
72
+ /**
73
+ * Starts the worker thread
74
+ *
75
+ * @returns A function to stop the worker
76
+ */
77
+ async function _startWorker(
78
+ client,
79
+ integrationOptions,
80
+ ) {
81
+ const dsn = client.getDsn();
82
+
83
+ if (!dsn) {
84
+ return () => {
85
+ //
86
+ };
87
+ }
88
+
89
+ const contexts = await getContexts(client);
90
+
91
+ // These will not be accurate if sent later from the worker thread
92
+ delete contexts.app?.app_memory;
93
+ delete contexts.device?.free_memory;
94
+
95
+ const initOptions = client.getOptions();
96
+
97
+ const sdkMetadata = client.getSdkMetadata() || {};
98
+ if (sdkMetadata.sdk) {
99
+ sdkMetadata.sdk.integrations = initOptions.integrations.map(i => i.name);
100
+ }
101
+
102
+ const options = {
103
+ debug: logger.isEnabled(),
104
+ dsn,
105
+ tunnel: initOptions.tunnel,
106
+ environment: initOptions.environment || 'production',
107
+ release: initOptions.release,
108
+ dist: initOptions.dist,
109
+ sdkMetadata,
110
+ appRootPath: integrationOptions.appRootPath,
111
+ threshold: integrationOptions.threshold || DEFAULT_THRESHOLD_MS,
112
+ maxEventsPerHour: integrationOptions.maxEventsPerHour || 1,
113
+ staticTags: integrationOptions.staticTags || {},
114
+ contexts,
115
+ };
116
+
117
+ const pollInterval = options.threshold / POLL_RATIO;
118
+
119
+ const worker = new Worker(new URL('./event-loop-block-watchdog.js', import.meta.url), {
120
+ workerData: options,
121
+ // We don't want any Node args like --import to be passed to the worker
122
+ execArgv: [],
123
+ env: { ...process.env, NODE_OPTIONS: undefined },
124
+ });
125
+
126
+ process.on('exit', () => {
127
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
128
+ worker.terminate();
129
+ });
130
+
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
+ worker.once('error', (err) => {
147
+ clearInterval(timer);
148
+ log('watchdog worker error', err);
149
+ });
150
+
151
+ worker.once('exit', (code) => {
152
+ clearInterval(timer);
153
+ log('watchdog worker exit', code);
154
+ });
155
+
156
+ // Ensure this thread can't block app exit
157
+ worker.unref();
158
+
159
+ return () => {
160
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
161
+ worker.terminate();
162
+ clearInterval(timer);
163
+ };
164
+ }
165
+
166
+ export { eventLoopBlockIntegration };
167
+ //# sourceMappingURL=event-loop-block-integration.js.map
@@ -0,0 +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":";;;;;AAQA,MAAM,oBAAA,GAAuB,IAAK;;AAElC,SAAS,GAAG,CAAC,OAAO,EAAU,GAAG,IAAI,EAAmB;AACxD,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,0BAA0B,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;;AAEA,MAAA,gBAAA,GA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AAA,EAAA,WAAA,EAAA,uBAAA,CAAA,WAAA,CAAA,WAAA,CAAA,EAAA,CAAA;AACA,KAAA,CAAA,OAAA,CAAA,EAAA;AACA;AACA;AACA,GAAA,EAAA,YAAA,CAAA;AACA;AACA,EAAA,KAAA,CAAA,KAAA,EAAA;;AAEA,EAAA,MAAA,CAAA,IAAA,CAAA,OAAA,EAAA,CAAA,GAAA,KAAA;AACA,IAAA,aAAA,CAAA,KAAA,CAAA;AACA,IAAA,GAAA,CAAA,uBAAA,EAAA,GAAA,CAAA;AACA,GAAA,CAAA;;AAEA,EAAA,MAAA,CAAA,IAAA,CAAA,MAAA,EAAA,CAAA,IAAA,KAAA;AACA,IAAA,aAAA,CAAA,KAAA,CAAA;AACA,IAAA,GAAA,CAAA,sBAAA,EAAA,IAAA,CAAA;AACA,GAAA,CAAA;;AAEA;AACA,EAAA,MAAA,CAAA,KAAA,EAAA;;AAEA,EAAA,OAAA,MAAA;AACA;AACA,IAAA,MAAA,CAAA,SAAA,EAAA;AACA,IAAA,aAAA,CAAA,KAAA,CAAA;AACA,GAAA;AACA;;;;"}
@@ -0,0 +1,275 @@
1
+ import { workerData } from 'node:worker_threads';
2
+ import { getEnvelopeEndpointWithUrlEncodedAuth, uuid4, createEventEnvelope, makeSession, updateSession, createSessionEnvelope, normalizeUrlToBase, stripSentryFramesAndReverse, filenameIsInApp } from '@sentry/core';
3
+ import { makeNodeTransport } from '@sentry/node';
4
+ import { getThreadsLastSeen, captureStackTrace } from '@sentry-internal/node-native-stacktrace';
5
+ import { POLL_RATIO } from './common.js';
6
+
7
+ const {
8
+ threshold,
9
+ appRootPath,
10
+ contexts,
11
+ debug,
12
+ dist,
13
+ dsn,
14
+ environment,
15
+ maxEventsPerHour,
16
+ release,
17
+ sdkMetadata,
18
+ staticTags: tags,
19
+ tunnel,
20
+ } = workerData ;
21
+
22
+ const pollInterval = threshold / POLL_RATIO;
23
+ const triggeredThreads = new Set();
24
+
25
+ function log(...msg) {
26
+ if (debug) {
27
+ // eslint-disable-next-line no-console
28
+ console.log('[Sentry Block Event Loop Watchdog]', ...msg);
29
+ }
30
+ }
31
+
32
+ function createRateLimiter(maxEventsPerHour) {
33
+ let currentHour = 0;
34
+ let currentCount = 0;
35
+
36
+ return function isRateLimited() {
37
+ const hour = new Date().getHours();
38
+
39
+ if (hour !== currentHour) {
40
+ currentHour = hour;
41
+ currentCount = 0;
42
+ }
43
+
44
+ if (currentCount >= maxEventsPerHour) {
45
+ if (currentCount === maxEventsPerHour) {
46
+ currentCount += 1;
47
+ log(`Rate limit reached: ${currentCount} events in this hour`);
48
+ }
49
+ return true;
50
+ }
51
+
52
+ currentCount += 1;
53
+ return false;
54
+ };
55
+ }
56
+
57
+ const url = getEnvelopeEndpointWithUrlEncodedAuth(dsn, tunnel, sdkMetadata.sdk);
58
+ const transport = makeNodeTransport({
59
+ url,
60
+ recordDroppedEvent: () => {
61
+ //
62
+ },
63
+ });
64
+ const isRateLimited = createRateLimiter(maxEventsPerHour);
65
+
66
+ async function sendAbnormalSession(serializedSession) {
67
+ if (!serializedSession) {
68
+ return;
69
+ }
70
+
71
+ log('Sending abnormal session');
72
+ const session = makeSession(serializedSession);
73
+
74
+ updateSession(session, {
75
+ status: 'abnormal',
76
+ abnormal_mechanism: 'anr_foreground',
77
+ release,
78
+ environment,
79
+ });
80
+
81
+ const envelope = createSessionEnvelope(session, dsn, sdkMetadata, tunnel);
82
+ // Log the envelope so to aid in testing
83
+ log(JSON.stringify(envelope));
84
+
85
+ await transport.send(envelope);
86
+ }
87
+
88
+ log('Started');
89
+
90
+ function prepareStackFrames(stackFrames) {
91
+ if (!stackFrames) {
92
+ return undefined;
93
+ }
94
+
95
+ // Strip Sentry frames and reverse the stack frames so they are in the correct order
96
+ const strippedFrames = stripSentryFramesAndReverse(stackFrames);
97
+
98
+ for (const frame of strippedFrames) {
99
+ if (!frame.filename) {
100
+ continue;
101
+ }
102
+
103
+ frame.in_app = filenameIsInApp(frame.filename);
104
+
105
+ // If we have an app root path, rewrite the filenames to be relative to the app root
106
+ if (appRootPath) {
107
+ frame.filename = normalizeUrlToBase(frame.filename, appRootPath);
108
+ }
109
+ }
110
+
111
+ return strippedFrames;
112
+ }
113
+
114
+ function stripFileProtocol(filename) {
115
+ if (!filename) {
116
+ return undefined;
117
+ }
118
+ return filename.replace(/^file:\/\//, '');
119
+ }
120
+
121
+ // eslint-disable-next-line complexity
122
+ function applyDebugMeta(event, debugImages) {
123
+ if (Object.keys(debugImages).length === 0) {
124
+ return;
125
+ }
126
+
127
+ const normalisedDebugImages = appRootPath ? {} : debugImages;
128
+ if (appRootPath) {
129
+ for (const [path, debugId] of Object.entries(debugImages)) {
130
+ normalisedDebugImages[normalizeUrlToBase(path, appRootPath)] = debugId;
131
+ }
132
+ }
133
+
134
+ const filenameToDebugId = new Map();
135
+
136
+ for (const exception of event.exception?.values || []) {
137
+ for (const frame of exception.stacktrace?.frames || []) {
138
+ const filename = stripFileProtocol(frame.abs_path || frame.filename);
139
+ if (filename && normalisedDebugImages[filename]) {
140
+ filenameToDebugId.set(filename, normalisedDebugImages[filename] );
141
+ }
142
+ }
143
+ }
144
+
145
+ for (const thread of event.threads?.values || []) {
146
+ for (const frame of thread.stacktrace?.frames || []) {
147
+ const filename = stripFileProtocol(frame.abs_path || frame.filename);
148
+ if (filename && normalisedDebugImages[filename]) {
149
+ filenameToDebugId.set(filename, normalisedDebugImages[filename] );
150
+ }
151
+ }
152
+ }
153
+
154
+ if (filenameToDebugId.size > 0) {
155
+ const images = [];
156
+ for (const [code_file, debug_id] of filenameToDebugId.entries()) {
157
+ images.push({
158
+ type: 'sourcemap',
159
+ code_file,
160
+ debug_id,
161
+ });
162
+ }
163
+ event.debug_meta = { images };
164
+ }
165
+ }
166
+
167
+ function getExceptionAndThreads(
168
+ crashedThreadId,
169
+ threads,
170
+ ) {
171
+ const crashedThread = threads[crashedThreadId];
172
+
173
+ return {
174
+ exception: {
175
+ values: [
176
+ {
177
+ type: 'EventLoopBlocked',
178
+ value: `Event Loop Blocked for at least ${threshold} ms`,
179
+ stacktrace: { frames: prepareStackFrames(crashedThread?.frames) },
180
+ // This ensures the UI doesn't say 'Crashed in' for the stack trace
181
+ mechanism: { type: 'ANR' },
182
+ thread_id: crashedThreadId,
183
+ },
184
+ ],
185
+ },
186
+ threads: {
187
+ values: Object.entries(threads).map(([threadId, threadState]) => {
188
+ const crashed = threadId === crashedThreadId;
189
+
190
+ const thread = {
191
+ id: threadId,
192
+ name: threadId === '0' ? 'main' : `worker-${threadId}`,
193
+ crashed,
194
+ current: true,
195
+ main: threadId === '0',
196
+ };
197
+
198
+ if (!crashed) {
199
+ thread.stacktrace = { frames: prepareStackFrames(threadState.frames) };
200
+ }
201
+
202
+ return thread;
203
+ }),
204
+ },
205
+ };
206
+ }
207
+
208
+ async function sendBlockEvent(crashedThreadId) {
209
+ if (isRateLimited()) {
210
+ return;
211
+ }
212
+
213
+ const threads = captureStackTrace();
214
+ const crashedThread = threads[crashedThreadId];
215
+
216
+ if (!crashedThread) {
217
+ log(`No thread found with ID '${crashedThreadId}'`);
218
+ return;
219
+ }
220
+
221
+ try {
222
+ await sendAbnormalSession(crashedThread.state?.session);
223
+ } catch (error) {
224
+ log(`Failed to send abnormal session for thread '${crashedThreadId}':`, error);
225
+ }
226
+
227
+ log('Sending event');
228
+
229
+ const event = {
230
+ event_id: uuid4(),
231
+ contexts,
232
+ release,
233
+ environment,
234
+ dist,
235
+ platform: 'node',
236
+ level: 'error',
237
+ tags,
238
+ ...getExceptionAndThreads(crashedThreadId, threads),
239
+ };
240
+
241
+ const allDebugImages = Object.values(threads).reduce((acc, threadState) => {
242
+ return { ...acc, ...threadState.state?.debugImages };
243
+ }, {});
244
+
245
+ applyDebugMeta(event, allDebugImages);
246
+
247
+ const envelope = createEventEnvelope(event, dsn, sdkMetadata, tunnel);
248
+ // Log the envelope to aid in testing
249
+ log(JSON.stringify(envelope));
250
+
251
+ await transport.send(envelope);
252
+ await transport.flush(2000);
253
+ }
254
+
255
+ setInterval(async () => {
256
+ for (const [threadId, time] of Object.entries(getThreadsLastSeen())) {
257
+ if (time > threshold) {
258
+ if (triggeredThreads.has(threadId)) {
259
+ continue;
260
+ }
261
+
262
+ log(`Blocked thread detected '${threadId}' last polled ${time} ms ago.`);
263
+ triggeredThreads.add(threadId);
264
+
265
+ try {
266
+ await sendBlockEvent(threadId);
267
+ } catch (error) {
268
+ log(`Failed to send event for thread '${threadId}':`, error);
269
+ }
270
+ } else {
271
+ triggeredThreads.delete(threadId);
272
+ }
273
+ }
274
+ }, pollInterval);
275
+ //# sourceMappingURL=event-loop-block-watchdog.js.map
@@ -0,0 +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,EA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GAAA,EAAA,GAAA,WAAA,CAAA,KAAA,EAAA,WAAA,EAAA;AACA,GAAA,EAAA,EAAA,CAAA;;AAEA,EAAA,cAAA,CAAA,KAAA,EAAA,cAAA,CAAA;;AAEA,EAAA,MAAA,QAAA,GAAA,mBAAA,CAAA,KAAA,EAAA,GAAA,EAAA,WAAA,EAAA,MAAA,CAAA;AACA;AACA,EAAA,GAAA,CAAA,IAAA,CAAA,SAAA,CAAA,QAAA,CAAA,CAAA;;AAEA,EAAA,MAAA,SAAA,CAAA,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,CAAA,kBAAA,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"}
@@ -0,0 +1,2 @@
1
+ export { eventLoopBlockIntegration } from './event-loop-block-integration.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ {"type":"module","version":"9.38.0","sideEffects":false}
@@ -0,0 +1,43 @@
1
+ import type { Contexts, DsnComponents, Primitive, SdkMetadata, Session } from '@sentry/core';
2
+ export declare const POLL_RATIO = 2;
3
+ export interface ThreadBlockedIntegrationOptions {
4
+ /**
5
+ * Threshold in milliseconds to trigger an event.
6
+ *
7
+ * Defaults to 1000ms.
8
+ */
9
+ threshold: number;
10
+ /**
11
+ * Maximum number of blocked events to send per clock hour.
12
+ *
13
+ * Defaults to 1.
14
+ */
15
+ maxEventsPerHour: number;
16
+ /**
17
+ * Tags to include with blocked events.
18
+ */
19
+ staticTags: {
20
+ [key: string]: Primitive;
21
+ };
22
+ /**
23
+ * @ignore Internal use only.
24
+ *
25
+ * If this is supplied, stack frame filenames will be rewritten to be relative to this path.
26
+ */
27
+ appRootPath: string | undefined;
28
+ }
29
+ export interface WorkerStartData extends ThreadBlockedIntegrationOptions {
30
+ debug: boolean;
31
+ sdkMetadata: SdkMetadata;
32
+ dsn: DsnComponents;
33
+ tunnel: string | undefined;
34
+ release: string | undefined;
35
+ environment: string;
36
+ dist: string | undefined;
37
+ contexts: Contexts;
38
+ }
39
+ export interface ThreadState {
40
+ session: Session | undefined;
41
+ debugImages: Record<string, string>;
42
+ }
43
+ //# sourceMappingURL=common.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/common.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,SAAS,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE7F,eAAO,MAAM,UAAU,IAAI,CAAC;AAE5B,MAAM,WAAW,+BAA+B;IAC9C;;;;OAIG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,gBAAgB,EAAE,MAAM,CAAC;IACzB;;OAEG;IACH,UAAU,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE,CAAC;IACzC;;;;OAIG;IACH,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;CACjC;AAED,MAAM,WAAW,eAAgB,SAAQ,+BAA+B;IACtE,KAAK,EAAE,OAAO,CAAC;IACf,WAAW,EAAE,WAAW,CAAC;IACzB,GAAG,EAAE,aAAa,CAAC;IACnB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,QAAQ,EAAE,QAAQ,CAAC;CACpB;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,OAAO,GAAG,SAAS,CAAC;IAC7B,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACrC"}
@@ -0,0 +1,32 @@
1
+ import type { ThreadBlockedIntegrationOptions } from './common';
2
+ /**
3
+ * Monitors the Node.js event loop for blocking behavior and reports blocked events to Sentry.
4
+ *
5
+ * Uses a background worker thread to detect when the main thread is blocked for longer than
6
+ * the configured threshold (default: 1 second).
7
+ *
8
+ * When instrumenting via the `--import` flag, this integration will
9
+ * automatically monitor all worker threads as well.
10
+ *
11
+ * ```js
12
+ * // instrument.mjs
13
+ * import * as Sentry from '@sentry/node';
14
+ * import { eventLoopBlockIntegration } from '@sentry/node-native';
15
+ *
16
+ * Sentry.init({
17
+ * dsn: '__YOUR_DSN__',
18
+ * integrations: [
19
+ * eventLoopBlockIntegration({
20
+ * threshold: 500, // Report blocks longer than 500ms
21
+ * }),
22
+ * ],
23
+ * });
24
+ * ```
25
+ *
26
+ * Start your application with:
27
+ * ```bash
28
+ * node --import instrument.mjs app.mjs
29
+ * ```
30
+ */
31
+ export declare const eventLoopBlockIntegration: (options?: Partial<ThreadBlockedIntegrationOptions> | undefined) => import("@sentry/core").Integration;
32
+ //# sourceMappingURL=event-loop-block-integration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-loop-block-integration.d.ts","sourceRoot":"","sources":["../../src/event-loop-block-integration.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,+BAA+B,EAAmB,MAAM,UAAU,CAAC;AAsCjF;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,yBAAyB,wGAAgD,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=event-loop-block-watchdog.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-loop-block-watchdog.d.ts","sourceRoot":"","sources":["../../src/event-loop-block-watchdog.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export { eventLoopBlockIntegration } from './event-loop-block-integration';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC"}
@@ -0,0 +1,43 @@
1
+ import { Contexts, DsnComponents, Primitive, SdkMetadata, Session } from '@sentry/core';
2
+ export declare const POLL_RATIO = 2;
3
+ export interface ThreadBlockedIntegrationOptions {
4
+ /**
5
+ * Threshold in milliseconds to trigger an event.
6
+ *
7
+ * Defaults to 1000ms.
8
+ */
9
+ threshold: number;
10
+ /**
11
+ * Maximum number of blocked events to send per clock hour.
12
+ *
13
+ * Defaults to 1.
14
+ */
15
+ maxEventsPerHour: number;
16
+ /**
17
+ * Tags to include with blocked events.
18
+ */
19
+ staticTags: {
20
+ [key: string]: Primitive;
21
+ };
22
+ /**
23
+ * @ignore Internal use only.
24
+ *
25
+ * If this is supplied, stack frame filenames will be rewritten to be relative to this path.
26
+ */
27
+ appRootPath: string | undefined;
28
+ }
29
+ export interface WorkerStartData extends ThreadBlockedIntegrationOptions {
30
+ debug: boolean;
31
+ sdkMetadata: SdkMetadata;
32
+ dsn: DsnComponents;
33
+ tunnel: string | undefined;
34
+ release: string | undefined;
35
+ environment: string;
36
+ dist: string | undefined;
37
+ contexts: Contexts;
38
+ }
39
+ export interface ThreadState {
40
+ session: Session | undefined;
41
+ debugImages: Record<string, string>;
42
+ }
43
+ //# sourceMappingURL=common.d.ts.map