Skip to content

Commit 7fb37dc

Browse files
committed
Remove disableBlockedDetectionForCallback for now
1 parent 487e667 commit 7fb37dc

File tree

2 files changed

+9
-63
lines changed

2 files changed

+9
-63
lines changed

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

Lines changed: 8 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
import { types } from 'node:util';
21
import { Worker } from 'node:worker_threads';
3-
import type { Contexts, Event, EventHint, Integration, IntegrationFn } from '@sentry/core';
4-
import { defineIntegration, getClient, getFilenameToDebugIdMap, getIsolationScope, logger } from '@sentry/core';
2+
import type { Contexts, Event, EventHint, IntegrationFn } from '@sentry/core';
3+
import { defineIntegration, getFilenameToDebugIdMap, getIsolationScope, logger } from '@sentry/core';
54
import type { NodeClient } from '@sentry/node';
65
import { registerThread, threadPoll } from '@sentry-internal/node-native-stacktrace';
76
import type { ThreadBlockedIntegrationOptions, WorkerStartData } from './common';
87
import { POLL_RATIO } from './common';
98

10-
const { isPromise } = types;
11-
129
const DEFAULT_THRESHOLD_MS = 1_000;
1310

1411
function log(message: string, ...args: unknown[]): void {
@@ -32,43 +29,18 @@ async function getContexts(client: NodeClient): Promise<Contexts> {
3229

3330
const INTEGRATION_NAME = 'ThreadBlocked';
3431

35-
type ThreadBlockedInternal = { start: () => void; stop: () => void };
36-
3732
const _eventLoopBlockIntegration = ((options: Partial<ThreadBlockedIntegrationOptions> = {}) => {
38-
let worker: Promise<() => void> | undefined;
39-
let client: NodeClient | undefined;
40-
4133
return {
4234
name: INTEGRATION_NAME,
43-
start: () => {
44-
if (worker) {
45-
return;
46-
}
47-
48-
if (client) {
49-
worker = _startWorker(client, options);
50-
}
51-
},
52-
stop: () => {
53-
if (worker) {
54-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
55-
worker.then(stop => {
56-
stop();
57-
worker = undefined;
58-
});
59-
}
60-
},
61-
afterAllSetup(initClient: NodeClient) {
62-
client = initClient;
63-
35+
afterAllSetup(client: NodeClient) {
6436
registerThread();
65-
this.start();
37+
_startWorker(client, options).catch(err => {
38+
log('Failed to start event loop block worker', err);
39+
});
6640
},
67-
} as Integration & ThreadBlockedInternal;
41+
};
6842
}) satisfies IntegrationFn;
6943

70-
type ThreadBlockedReturn = (options?: Partial<ThreadBlockedIntegrationOptions>) => Integration & ThreadBlockedInternal;
71-
7244
/**
7345
* Monitors the Node.js event loop for blocking behavior and reports blocked events to Sentry.
7446
*
@@ -98,7 +70,7 @@ type ThreadBlockedReturn = (options?: Partial<ThreadBlockedIntegrationOptions>)
9870
* node --import instrument.mjs app.mjs
9971
* ```
10072
*/
101-
export const eventLoopBlockIntegration = defineIntegration(_eventLoopBlockIntegration) as ThreadBlockedReturn;
73+
export const eventLoopBlockIntegration = defineIntegration(_eventLoopBlockIntegration);
10274

10375
/**
10476
* Starts the worker thread
@@ -193,29 +165,3 @@ async function _startWorker(
193165
clearInterval(timer);
194166
};
195167
}
196-
197-
export function disableBlockedDetectionForCallback<T>(callback: () => T): T;
198-
export function disableBlockedDetectionForCallback<T>(callback: () => Promise<T>): Promise<T>;
199-
/**
200-
* Disables blocked detection for the duration of the callback
201-
*/
202-
export function disableBlockedDetectionForCallback<T>(callback: () => T | Promise<T>): T | Promise<T> {
203-
const integration = getClient()?.getIntegrationByName(INTEGRATION_NAME) as ThreadBlockedInternal | undefined;
204-
205-
if (!integration) {
206-
return callback();
207-
}
208-
209-
integration.stop();
210-
211-
const result = callback();
212-
if (isPromise(result)) {
213-
return result.finally(() => integration.start());
214-
}
215-
216-
try {
217-
return result;
218-
} finally {
219-
integration.start();
220-
}
221-
}

packages/node-native/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export { eventLoopBlockIntegration, disableBlockedDetectionForCallback } from './event-loop-block-integration';
1+
export { eventLoopBlockIntegration } from './event-loop-block-integration';

0 commit comments

Comments
 (0)