diff --git a/packages/node/src/sdk/index.ts b/packages/node/src/sdk/index.ts index 746136c03022..4c30ba2bd2cf 100644 --- a/packages/node/src/sdk/index.ts +++ b/packages/node/src/sdk/index.ts @@ -130,7 +130,7 @@ function _init( } } - if (!isCjs()) { + if (!isCjs() && options.registerEsmLoaderHooks !== false) { maybeInitializeEsmLoader(); } diff --git a/packages/node/src/types.ts b/packages/node/src/types.ts index 2c00302e2e64..882114a013f9 100644 --- a/packages/node/src/types.ts +++ b/packages/node/src/types.ts @@ -85,6 +85,16 @@ export interface BaseNodeOptions { */ maxSpanWaitDuration?: number; + /** + * Whether to register ESM loader hooks to automatically instrument libraries. + * This is necessary to auto instrument libraries that are loaded via ESM imports, but might it can cause issues + * with certain libraries. If you run into problems running your app with this enabled, + * please raise an issue in https://github.com/getsentry/sentry-javascript. + * + * Defaults to `true`. + */ + registerEsmLoaderHooks?: boolean; + /** Callback that is executed when a fatal global error occurs. */ onFatalError?(this: void, error: Error): void; }