Skip to content

Commit 22d1f96

Browse files
lforstmydea
authored andcommitted
feat(node)!: Remove fine grained registerEsmLoaderHooks option and addOpenTelemetryInstrumentation()
1 parent 7846b24 commit 22d1f96

File tree

13 files changed

+9
-113
lines changed

13 files changed

+9
-113
lines changed

packages/astro/src/index.server.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ export {
1212
addEventProcessor,
1313
addIntegration,
1414
// eslint-disable-next-line deprecation/deprecation
15-
addOpenTelemetryInstrumentation,
16-
// eslint-disable-next-line deprecation/deprecation
1715
addRequestDataToEvent,
1816
amqplibIntegration,
1917
anrIntegration,

packages/aws-serverless/src/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,6 @@ export {
121121
spanToTraceHeader,
122122
spanToBaggageHeader,
123123
trpcMiddleware,
124-
// eslint-disable-next-line deprecation/deprecation
125-
addOpenTelemetryInstrumentation,
126124
zodErrorsIntegration,
127125
profiler,
128126
amqplibIntegration,

packages/bun/src/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,6 @@ export {
141141
spanToTraceHeader,
142142
spanToBaggageHeader,
143143
trpcMiddleware,
144-
// eslint-disable-next-line deprecation/deprecation
145-
addOpenTelemetryInstrumentation,
146144
zodErrorsIntegration,
147145
profiler,
148146
amqplibIntegration,

packages/google-cloud-serverless/src/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,6 @@ export {
118118
spanToTraceHeader,
119119
spanToBaggageHeader,
120120
trpcMiddleware,
121-
// eslint-disable-next-line deprecation/deprecation
122-
addOpenTelemetryInstrumentation,
123121
zodErrorsIntegration,
124122
profiler,
125123
amqplibIntegration,

packages/node/src/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ export type { NodeOptions } from './types';
6161
export { addRequestDataToEvent, DEFAULT_USER_INCLUDES, extractRequestData } from '@sentry/core';
6262

6363
export {
64-
// eslint-disable-next-line deprecation/deprecation
65-
addOpenTelemetryInstrumentation,
6664
// These are custom variants that need to be used instead of the core one
6765
// As they have slightly different implementations
6866
continueTrace,

packages/node/src/sdk/index.ts

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

134134
if (!isCjs() && options.registerEsmLoaderHooks !== false) {
135-
maybeInitializeEsmLoader(options.registerEsmLoaderHooks === true ? undefined : options.registerEsmLoaderHooks);
135+
maybeInitializeEsmLoader();
136136
}
137137

138138
setOpenTelemetryContextAsyncContextStrategy();

packages/node/src/sdk/initOtel.ts

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { SentryPropagator, SentrySampler, SentrySpanProcessor } from '@sentry/op
1212
import { createAddHookMessageChannel } from 'import-in-the-middle';
1313
import { getOpenTelemetryInstrumentationToPreload } from '../integrations/tracing';
1414
import { SentryContextManager } from '../otel/contextManager';
15-
import type { EsmLoaderHookOptions } from '../types';
1615
import { isCjs } from '../utils/commonjs';
1716
import type { NodeClient } from './client';
1817

@@ -30,30 +29,8 @@ export function initOpenTelemetry(client: NodeClient): void {
3029
client.traceProvider = provider;
3130
}
3231

33-
type ImportInTheMiddleInitData = Pick<EsmLoaderHookOptions, 'include' | 'exclude'> & {
34-
addHookMessagePort?: unknown;
35-
};
36-
37-
interface RegisterOptions {
38-
data?: ImportInTheMiddleInitData;
39-
transferList?: unknown[];
40-
}
41-
42-
function getRegisterOptions(esmHookConfig?: EsmLoaderHookOptions): RegisterOptions {
43-
// TODO(v9): Make onlyIncludeInstrumentedModules: true the default behavior.
44-
if (esmHookConfig?.onlyIncludeInstrumentedModules) {
45-
const { addHookMessagePort } = createAddHookMessageChannel();
46-
// If the user supplied include, we need to use that as a starting point or use an empty array to ensure no modules
47-
// are wrapped if they are not hooked
48-
// eslint-disable-next-line deprecation/deprecation
49-
return { data: { addHookMessagePort, include: esmHookConfig.include || [] }, transferList: [addHookMessagePort] };
50-
}
51-
52-
return { data: esmHookConfig };
53-
}
54-
5532
/** Initialize the ESM loader. */
56-
export function maybeInitializeEsmLoader(esmHookConfig?: EsmLoaderHookOptions): void {
33+
export function maybeInitializeEsmLoader(): void {
5734
const [nodeMajor = 0, nodeMinor = 0] = process.versions.node.split('.').map(Number);
5835

5936
// Register hook was added in v20.6.0 and v18.19.0
@@ -64,8 +41,12 @@ export function maybeInitializeEsmLoader(esmHookConfig?: EsmLoaderHookOptions):
6441

6542
if (!GLOBAL_OBJ._sentryEsmLoaderHookRegistered && importMetaUrl) {
6643
try {
44+
const { addHookMessagePort } = createAddHookMessageChannel();
6745
// @ts-expect-error register is available in these versions
68-
moduleModule.register('import-in-the-middle/hook.mjs', importMetaUrl, getRegisterOptions(esmHookConfig));
46+
moduleModule.register('import-in-the-middle/hook.mjs', importMetaUrl, {
47+
data: { addHookMessagePort },
48+
transferList: [addHookMessagePort],
49+
});
6950
GLOBAL_OBJ._sentryEsmLoaderHookRegistered = true;
7051
} catch (error) {
7152
logger.warn('Failed to register ESM hook', error);
@@ -84,7 +65,6 @@ export function maybeInitializeEsmLoader(esmHookConfig?: EsmLoaderHookOptions):
8465
interface NodePreloadOptions {
8566
debug?: boolean;
8667
integrations?: string[];
87-
registerEsmLoaderHooks?: EsmLoaderHookOptions;
8868
}
8969

9070
/**
@@ -101,7 +81,7 @@ export function preloadOpenTelemetry(options: NodePreloadOptions = {}): void {
10181
}
10282

10383
if (!isCjs()) {
104-
maybeInitializeEsmLoader(options.registerEsmLoaderHooks);
84+
maybeInitializeEsmLoader();
10585
}
10686

10787
// These are all integrations that we need to pre-load to ensure they are set up before any other code runs

packages/node/src/types.ts

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -5,43 +5,6 @@ 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-
*/
12-
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-
*/
18-
include?: 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-
/**
28-
* When set to `true`, `import-in-the-middle` will only wrap ESM modules that are specifically instrumented by
29-
* OpenTelemetry plugins. This is useful to avoid issues where `import-in-the-middle` is not compatible with some of
30-
* your dependencies.
31-
*
32-
* **Note**: This feature will only work if you `Sentry.init()` the SDK before the instrumented modules are loaded.
33-
* This can be achieved via the Node `--import` CLI flag or by loading your app via async `import()` after calling
34-
* `Sentry.init()`.
35-
*
36-
* Defaults to `false`.
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.
42-
onlyIncludeInstrumentedModules?: boolean;
43-
}
44-
458
export interface BaseNodeOptions {
469
/**
4710
* List of strings/regex controlling to which outgoing requests
@@ -138,22 +101,9 @@ export interface BaseNodeOptions {
138101
* with certain libraries. If you run into problems running your app with this enabled,
139102
* please raise an issue in https://github.com/getsentry/sentry-javascript.
140103
*
141-
* You can optionally exclude specific modules or only include specific modules from being instrumented by providing
142-
* an object with `include` or `exclude` properties.
143-
*
144-
* ```js
145-
* registerEsmLoaderHooks: {
146-
* exclude: ['openai'],
147-
* }
148-
* ```
149-
*
150104
* 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`.
154105
*/
155-
// TODO(v9): Only accept true | false | undefined.
156-
registerEsmLoaderHooks?: boolean | EsmLoaderHookOptions;
106+
registerEsmLoaderHooks?: boolean;
157107

158108
/**
159109
* Configures in which interval client reports will be flushed. Defaults to `60_000` (milliseconds).

packages/opentelemetry/src/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,5 @@ export {
5858

5959
export { openTelemetrySetupCheck } from './utils/setupCheck';
6060

61-
// eslint-disable-next-line deprecation/deprecation
62-
export { addOpenTelemetryInstrumentation } from './instrumentation';
63-
6461
// Legacy
6562
export { getClient } from '@sentry/core';

packages/opentelemetry/src/instrumentation.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

packages/remix/src/index.server.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ export {
1616
addEventProcessor,
1717
addIntegration,
1818
// eslint-disable-next-line deprecation/deprecation
19-
addOpenTelemetryInstrumentation,
20-
// eslint-disable-next-line deprecation/deprecation
2119
addRequestDataToEvent,
2220
amqplibIntegration,
2321
anrIntegration,

packages/solidstart/src/server/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ export {
88
addEventProcessor,
99
addIntegration,
1010
// eslint-disable-next-line deprecation/deprecation
11-
addOpenTelemetryInstrumentation,
12-
// eslint-disable-next-line deprecation/deprecation
1311
addRequestDataToEvent,
1412
amqplibIntegration,
1513
anrIntegration,

packages/sveltekit/src/server/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ export {
88
addEventProcessor,
99
addIntegration,
1010
// eslint-disable-next-line deprecation/deprecation
11-
addOpenTelemetryInstrumentation,
12-
// eslint-disable-next-line deprecation/deprecation
1311
addRequestDataToEvent,
1412
amqplibIntegration,
1513
anrIntegration,

0 commit comments

Comments
 (0)