Skip to content

Commit c8f1661

Browse files
authored
ref(node): Handle failing hook registration gracefully (#12135)
Hopefully fixes #12114??
1 parent 77ff5d9 commit c8f1661

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

packages/node/src/sdk/init.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,13 @@ function _init(
142142
typeof __IMPORT_META_URL_REPLACEMENT__ !== 'undefined' ? __IMPORT_META_URL_REPLACEMENT__ : undefined;
143143

144144
if (!GLOBAL_OBJ._sentryEsmLoaderHookRegistered && importMetaUrl) {
145-
// @ts-expect-error register is available in these versions
146-
moduleModule.register('@opentelemetry/instrumentation/hook.mjs', importMetaUrl);
147-
GLOBAL_OBJ._sentryEsmLoaderHookRegistered = true;
145+
try {
146+
// @ts-expect-error register is available in these versions
147+
moduleModule.register('@opentelemetry/instrumentation/hook.mjs', importMetaUrl);
148+
GLOBAL_OBJ._sentryEsmLoaderHookRegistered = true;
149+
} catch (error) {
150+
logger.warn('Failed to register ESM hook', error);
151+
}
148152
}
149153
} else {
150154
consoleSandbox(() => {

0 commit comments

Comments
 (0)