@@ -12,7 +12,6 @@ import { SentryPropagator, SentrySampler, SentrySpanProcessor } from '@sentry/op
1212import { createAddHookMessageChannel } from 'import-in-the-middle' ;
1313import { getOpenTelemetryInstrumentationToPreload } from '../integrations/tracing' ;
1414import { SentryContextManager } from '../otel/contextManager' ;
15- import type { EsmLoaderHookOptions } from '../types' ;
1615import { isCjs } from '../utils/commonjs' ;
1716import type { NodeClient } from './client' ;
1817
@@ -30,30 +29,8 @@ export function initOpenTelemetry(client: NodeClient): void {
3029 client . traceProvider = provider ;
3130}
3231
33- type ImportInTheMiddleInitData = Pick < EsmLoaderHookOptions , 'include' | 'exclude' > & {
34- addHookMessagePort ?: unknown ;
35- } ;
36-
37- interface RegisterOptions {
38- data ?: ImportInTheMiddleInitData ;
39- transferList ?: unknown [ ] ;
40- }
41-
42- function getRegisterOptions ( esmHookConfig ?: EsmLoaderHookOptions ) : RegisterOptions {
43- // TODO(v9): Make onlyIncludeInstrumentedModules: true the default behavior.
44- if ( esmHookConfig ?. onlyIncludeInstrumentedModules ) {
45- const { addHookMessagePort } = createAddHookMessageChannel ( ) ;
46- // If the user supplied include, we need to use that as a starting point or use an empty array to ensure no modules
47- // are wrapped if they are not hooked
48- // eslint-disable-next-line deprecation/deprecation
49- return { data : { addHookMessagePort, include : esmHookConfig . include || [ ] } , transferList : [ addHookMessagePort ] } ;
50- }
51-
52- return { data : esmHookConfig } ;
53- }
54-
5532/** Initialize the ESM loader. */
56- export function maybeInitializeEsmLoader ( esmHookConfig ?: EsmLoaderHookOptions ) : void {
33+ export function maybeInitializeEsmLoader ( ) : void {
5734 const [ nodeMajor = 0 , nodeMinor = 0 ] = process . versions . node . split ( '.' ) . map ( Number ) ;
5835
5936 // Register hook was added in v20.6.0 and v18.19.0
@@ -64,8 +41,12 @@ export function maybeInitializeEsmLoader(esmHookConfig?: EsmLoaderHookOptions):
6441
6542 if ( ! GLOBAL_OBJ . _sentryEsmLoaderHookRegistered && importMetaUrl ) {
6643 try {
44+ const { addHookMessagePort } = createAddHookMessageChannel ( ) ;
6745 // @ts -expect-error register is available in these versions
68- moduleModule . register ( 'import-in-the-middle/hook.mjs' , importMetaUrl , getRegisterOptions ( esmHookConfig ) ) ;
46+ moduleModule . register ( 'import-in-the-middle/hook.mjs' , importMetaUrl , {
47+ data : { addHookMessagePort } ,
48+ transferList : [ addHookMessagePort ] ,
49+ } ) ;
6950 GLOBAL_OBJ . _sentryEsmLoaderHookRegistered = true ;
7051 } catch ( error ) {
7152 logger . warn ( 'Failed to register ESM hook' , error ) ;
@@ -84,7 +65,6 @@ export function maybeInitializeEsmLoader(esmHookConfig?: EsmLoaderHookOptions):
8465interface NodePreloadOptions {
8566 debug ?: boolean ;
8667 integrations ?: string [ ] ;
87- registerEsmLoaderHooks ?: EsmLoaderHookOptions ;
8868}
8969
9070/**
@@ -101,7 +81,7 @@ export function preloadOpenTelemetry(options: NodePreloadOptions = {}): void {
10181 }
10282
10383 if ( ! isCjs ( ) ) {
104- maybeInitializeEsmLoader ( options . registerEsmLoaderHooks ) ;
84+ maybeInitializeEsmLoader ( ) ;
10585 }
10686
10787 // These are all integrations that we need to pre-load to ensure they are set up before any other code runs
0 commit comments