Skip to content

Commit 487e667

Browse files
committed
PR review
1 parent 66e6aa5 commit 487e667

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

packages/node-native/src/event-loop-block-integration.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ type ThreadBlockedReturn = (options?: Partial<ThreadBlockedIntegrationOptions>)
7373
* Monitors the Node.js event loop for blocking behavior and reports blocked events to Sentry.
7474
*
7575
* Uses a background worker thread to detect when the main thread is blocked for longer than
76-
* the configured threshold (default: 5 seconds).
76+
* the configured threshold (default: 1 second).
7777
*
7878
* When instrumenting via the `--import` flag, this integration will
7979
* automatically monitor all worker threads as well.
@@ -213,6 +213,9 @@ export function disableBlockedDetectionForCallback<T>(callback: () => T | Promis
213213
return result.finally(() => integration.start());
214214
}
215215

216-
integration.start();
217-
return result;
216+
try {
217+
return result;
218+
} finally {
219+
integration.start();
220+
}
218221
}

packages/node-native/src/event-loop-block-watchdog.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ function getExceptionAndThreads(
217217
};
218218
}
219219

220-
async function sendAnrEvent(crashedThreadId: string): Promise<void> {
220+
async function sendBlockEvent(crashedThreadId: string): Promise<void> {
221221
if (isRateLimited()) {
222222
return;
223223
}
@@ -230,7 +230,11 @@ async function sendAnrEvent(crashedThreadId: string): Promise<void> {
230230
return;
231231
}
232232

233-
await sendAbnormalSession(crashedThread.state?.session);
233+
try {
234+
await sendAbnormalSession(crashedThread.state?.session);
235+
} catch (error) {
236+
log(`Failed to send abnormal session for thread '${crashedThreadId}':`, error);
237+
}
234238

235239
log('Sending event');
236240

@@ -267,10 +271,14 @@ setInterval(async () => {
267271
continue;
268272
}
269273

270-
log(`Detected ANR for thread '${threadId}' with last seen time ${time} ms`);
274+
log(`Blocked thread detected '${threadId}' last polled ${time} ms ago.`);
271275
triggeredThreads.add(threadId);
272276

273-
await sendAnrEvent(threadId);
277+
try {
278+
await sendBlockEvent(threadId);
279+
} catch (error) {
280+
log(`Failed to send event for thread '${threadId}':`, error);
281+
}
274282
} else {
275283
triggeredThreads.delete(threadId);
276284
}

0 commit comments

Comments
 (0)