Skip to content

Commit 3e7969f

Browse files
authored
feat: Deprecate registerEsmLoaderHooks.include and registerEsmLoaderHooks.exclude (#14486)
1 parent 1e0cb04 commit 3e7969f

File tree

5 files changed

+40
-6
lines changed

5 files changed

+40
-6
lines changed

dev-packages/node-integration-tests/suites/esm/warn-esm/test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ afterAll(() => {
55
});
66

77
const esmWarning =
8-
'[Sentry] You are using Node.js in ESM mode ("import syntax"). The Sentry Node.js SDK is not compatible with ESM in Node.js versions before 18.19.0 or before 20.6.0. Please either build your application with CommonJS ("require() syntax"), or use version 7.x of the Sentry Node.js SDK.';
8+
'[Sentry] You are using Node.js in ESM mode ("import syntax"). The Sentry Node.js SDK is not compatible with ESM in Node.js versions before 18.19.0 or before 20.6.0. Please either build your application with CommonJS ("require() syntax"), or upgrade your Node.js version.';
99

1010
test("warns if using ESM on Node.js versions that don't support `register()`", async () => {
1111
const nodeMajorVersion = Number(process.versions.node.split('.')[0]);

docs/migration/draft-v9-migration-guide.md

+2
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,5 @@
9090
- Deprecated `processThreadBreadcrumbIntegration` in favor of `childProcessIntegration`. Functionally they are the same.
9191
- Deprecated `nestIntegration`. Use the NestJS SDK (`@sentry/nestjs`) instead.
9292
- Deprecated `setupNestErrorHandler`. Use the NestJS SDK (`@sentry/nestjs`) instead.
93+
- Deprecated `registerEsmLoaderHooks.include` and `registerEsmLoaderHooks.exclude`. Set `onlyIncludeInstrumentedModules: true` instead.
94+
- `registerEsmLoaderHooks` will only accept `true | false | undefined` in the future. The SDK will default to wrapping modules that are used as part of OpenTelemetry Instrumentation.

packages/node/src/sdk/initOtel.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,12 @@ interface RegisterOptions {
4242
}
4343

4444
function getRegisterOptions(esmHookConfig?: EsmLoaderHookOptions): RegisterOptions {
45+
// TODO(v9): Make onlyIncludeInstrumentedModules: true the default behavior.
4546
if (esmHookConfig?.onlyIncludeInstrumentedModules) {
4647
const { addHookMessagePort } = createAddHookMessageChannel();
4748
// If the user supplied include, we need to use that as a starting point or use an empty array to ensure no modules
4849
// are wrapped if they are not hooked
50+
// eslint-disable-next-line deprecation/deprecation
4951
return { data: { addHookMessagePort, include: esmHookConfig.include || [] }, transferList: [addHookMessagePort] };
5052
}
5153

@@ -75,7 +77,7 @@ export function maybeInitializeEsmLoader(esmHookConfig?: EsmLoaderHookOptions):
7577
consoleSandbox(() => {
7678
// eslint-disable-next-line no-console
7779
console.warn(
78-
'[Sentry] You are using Node.js in ESM mode ("import syntax"). The Sentry Node.js SDK is not compatible with ESM in Node.js versions before 18.19.0 or before 20.6.0. Please either build your application with CommonJS ("require() syntax"), or use version 7.x of the Sentry Node.js SDK.',
80+
'[Sentry] You are using Node.js in ESM mode ("import syntax"). The Sentry Node.js SDK is not compatible with ESM in Node.js versions before 18.19.0 or before 20.6.0. Please either build your application with CommonJS ("require() syntax"), or upgrade your Node.js version.',
7981
);
8082
});
8183
}

packages/node/src/types.ts

+29-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,26 @@ import type { ClientOptions, Options, SamplingContext, Scope, Span, TracePropaga
55

66
import type { NodeTransportOptions } from './transports';
77

8+
/**
9+
* Note: In the next major version of the Sentry SDK this interface will be removed and the SDK will by default only wrap
10+
* ESM modules that are required to be wrapped by OpenTelemetry Instrumentation.
11+
*/
812
export interface EsmLoaderHookOptions {
13+
/**
14+
* Provide a list of modules to wrap with `import-in-the-middle`.
15+
*
16+
* @deprecated It is recommended to use `onlyIncludeInstrumentedModules: true` instead of manually defining modules to include and exclude.
17+
*/
918
include?: Array<string | RegExp>;
10-
exclude?: Array<string | RegExp> /**
19+
20+
/**
21+
* Provide a list of modules to prevent them from being wrapped with `import-in-the-middle`.
22+
*
23+
* @deprecated It is recommended to use `onlyIncludeInstrumentedModules: true` instead of manually defining modules to include and exclude.
24+
*/
25+
exclude?: Array<string | RegExp>;
26+
27+
/**
1128
* When set to `true`, `import-in-the-middle` will only wrap ESM modules that are specifically instrumented by
1229
* OpenTelemetry plugins. This is useful to avoid issues where `import-in-the-middle` is not compatible with some of
1330
* your dependencies.
@@ -17,7 +34,11 @@ export interface EsmLoaderHookOptions {
1734
* `Sentry.init()`.
1835
*
1936
* Defaults to `false`.
20-
*/;
37+
*
38+
* Note: In the next major version of the Sentry SDK this option will be removed and the SDK will by default only wrap
39+
* ESM modules that are required to be wrapped by OpenTelemetry Instrumentation.
40+
*/
41+
// TODO(v9): Make `onlyIncludeInstrumentedModules: true` the default behavior.
2142
onlyIncludeInstrumentedModules?: boolean;
2243
}
2344

@@ -88,6 +109,8 @@ export interface BaseNodeOptions {
88109
* * The `SentryPropagator`
89110
* * The `SentryContextManager`
90111
* * The `SentrySampler`
112+
*
113+
* If you are registering your own OpenTelemetry Loader Hooks (or `import-in-the-middle` hooks), it is also recommended to set the `registerEsmLoaderHooks` option to false.
91114
*/
92115
skipOpenTelemetrySetup?: boolean;
93116

@@ -125,7 +148,11 @@ export interface BaseNodeOptions {
125148
* ```
126149
*
127150
* Defaults to `true`.
151+
*
152+
* Note: In the next major version of the SDK, the possibility to provide fine-grained control will be removed from this option.
153+
* This means that it will only be possible to pass `true` or `false`. The default value will continue to be `true`.
128154
*/
155+
// TODO(v9): Only accept true | false | undefined.
129156
registerEsmLoaderHooks?: boolean | EsmLoaderHookOptions;
130157

131158
/**

packages/nuxt/src/server/sdk.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,12 @@ export function mergeRegisterEsmLoaderHooks(
100100
): SentryNuxtServerOptions['registerEsmLoaderHooks'] {
101101
if (typeof options.registerEsmLoaderHooks === 'object' && options.registerEsmLoaderHooks !== null) {
102102
return {
103+
// eslint-disable-next-line deprecation/deprecation
103104
exclude: Array.isArray(options.registerEsmLoaderHooks.exclude)
104-
? [...options.registerEsmLoaderHooks.exclude, /vue/]
105-
: options.registerEsmLoaderHooks.exclude ?? [/vue/],
105+
? // eslint-disable-next-line deprecation/deprecation
106+
[...options.registerEsmLoaderHooks.exclude, /vue/]
107+
: // eslint-disable-next-line deprecation/deprecation
108+
options.registerEsmLoaderHooks.exclude ?? [/vue/],
106109
};
107110
}
108111
return options.registerEsmLoaderHooks ?? { exclude: [/vue/] };

0 commit comments

Comments
 (0)