Skip to content

Commit

Permalink
feat(node): Add registerEsmLoaderHooks option (#12684)
Browse files Browse the repository at this point in the history
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 <francesco.novy@sentry.io>
  • Loading branch information
timfish and mydea authored Jun 28, 2024
1 parent 5eafa40 commit c548c3c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/node/src/sdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ function _init(
}
}

if (!isCjs()) {
if (!isCjs() && options.registerEsmLoaderHooks !== false) {
maybeInitializeEsmLoader();
}

Expand Down
10 changes: 10 additions & 0 deletions packages/node/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit c548c3c

Please sign in to comment.