1
1
import { URL } from 'url' ;
2
2
import { defineIntegration , getCurrentScope } from '@sentry/core' ;
3
3
import type { Contexts , Event , EventHint , IntegrationFn } from '@sentry/types' ;
4
- import { dynamicRequire , logger } from '@sentry/utils' ;
5
- import type { Worker , WorkerOptions } from 'worker_threads' ;
4
+ import { logger } from '@sentry/utils' ;
5
+ import { Worker } from 'worker_threads' ;
6
6
import { NODE_MAJOR , NODE_VERSION } from '../../nodeVersion' ;
7
7
import type { NodeClient } from '../../sdk/client' ;
8
8
import type { AnrIntegrationOptions , WorkerStartData } from './common' ;
@@ -11,24 +11,10 @@ import { base64WorkerScript } from './worker-script';
11
11
const DEFAULT_INTERVAL = 50 ;
12
12
const DEFAULT_HANG_THRESHOLD = 5000 ;
13
13
14
- type WorkerNodeV14 = Worker & { new ( filename : string | URL , options ?: WorkerOptions ) : Worker } ;
15
-
16
- type WorkerThreads = {
17
- Worker : WorkerNodeV14 ;
18
- } ;
19
-
20
14
function log ( message : string , ...args : unknown [ ] ) : void {
21
15
logger . log ( `[ANR] ${ message } ` , ...args ) ;
22
16
}
23
17
24
- /**
25
- * We need to use dynamicRequire because worker_threads is not available in node < v12 and webpack error will when
26
- * targeting those versions
27
- */
28
- function getWorkerThreads ( ) : WorkerThreads {
29
- return dynamicRequire ( module , 'worker_threads' ) ;
30
- }
31
-
32
18
/**
33
19
* Gets contexts by calling all event processors. This relies on being called after all integrations are setup
34
20
*/
@@ -112,8 +98,6 @@ async function _startWorker(client: NodeClient, _options: Partial<AnrIntegration
112
98
}
113
99
}
114
100
115
- const { Worker } = getWorkerThreads ( ) ;
116
-
117
101
const worker = new Worker ( new URL ( `data:application/javascript;base64,${ base64WorkerScript } ` ) , {
118
102
workerData : options ,
119
103
} ) ;
0 commit comments