11import { URL } from 'url' ;
22import { defineIntegration , getCurrentScope } from '@sentry/core' ;
33import 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' ;
66import { NODE_MAJOR , NODE_VERSION } from '../../nodeVersion' ;
77import type { NodeClient } from '../../sdk/client' ;
88import type { AnrIntegrationOptions , WorkerStartData } from './common' ;
@@ -11,24 +11,10 @@ import { base64WorkerScript } from './worker-script';
1111const DEFAULT_INTERVAL = 50 ;
1212const DEFAULT_HANG_THRESHOLD = 5000 ;
1313
14- type WorkerNodeV14 = Worker & { new ( filename : string | URL , options ?: WorkerOptions ) : Worker } ;
15-
16- type WorkerThreads = {
17- Worker : WorkerNodeV14 ;
18- } ;
19-
2014function log ( message : string , ...args : unknown [ ] ) : void {
2115 logger . log ( `[ANR] ${ message } ` , ...args ) ;
2216}
2317
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-
3218/**
3319 * Gets contexts by calling all event processors. This relies on being called after all integrations are setup
3420 */
@@ -112,8 +98,6 @@ async function _startWorker(client: NodeClient, _options: Partial<AnrIntegration
11298 }
11399 }
114100
115- const { Worker } = getWorkerThreads ( ) ;
116-
117101 const worker = new Worker ( new URL ( `data:application/javascript;base64,${ base64WorkerScript } ` ) , {
118102 workerData : options ,
119103 } ) ;
0 commit comments