Skip to content

Commit c548c3c

Browse files
timfishmydea
andauthored
feat(node): Add registerEsmLoaderHooks option (#12684)
Currently the only way to disable ESM loader hook registration is to set: ```ts globalThis._sentryEsmLoaderHookRegistered = true; ``` After this PR, you can set the new `registerEsmLoaderHooks` option to `false`: ```ts import * as Sentry from '@sentry/node'; Sentry.init({ dsn: '__DSN__', registerEsmLoaderHooks: false, }); ``` --------- Co-authored-by: Francesco Novy <[email protected]>
1 parent 5eafa40 commit c548c3c

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

packages/node/src/sdk/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ function _init(
130130
}
131131
}
132132

133-
if (!isCjs()) {
133+
if (!isCjs() && options.registerEsmLoaderHooks !== false) {
134134
maybeInitializeEsmLoader();
135135
}
136136

packages/node/src/types.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,16 @@ export interface BaseNodeOptions {
8585
*/
8686
maxSpanWaitDuration?: number;
8787

88+
/**
89+
* Whether to register ESM loader hooks to automatically instrument libraries.
90+
* This is necessary to auto instrument libraries that are loaded via ESM imports, but might it can cause issues
91+
* with certain libraries. If you run into problems running your app with this enabled,
92+
* please raise an issue in https://github.com/getsentry/sentry-javascript.
93+
*
94+
* Defaults to `true`.
95+
*/
96+
registerEsmLoaderHooks?: boolean;
97+
8898
/** Callback that is executed when a fatal global error occurs. */
8999
onFatalError?(this: void, error: Error): void;
90100
}

0 commit comments

Comments
 (0)