Skip to content

Commit 5158f25

Browse files
andreiborzaclaude
andcommitted
ref(node)!: Remove @opentelemetry/instrumentation dependency
`@sentry/node` was the last package holding `@opentelemetry/instrumentation`. All instrumentation is now channel-based via orchestrion, so the surface this dependency backed is dead or a no-op: - `generateInstrumentOnce` (and the framework re-exports) had no call sites. - `ensureIsWrapped`'s shimmer-based check can no longer detect channel-based express/koa/hapi, so its warning and the `missing_instrumentation` context were removed, along with the `disableInstrumentationWarnings` option and the `MissingInstrumentationContext` type. - The `@sentry/node/import` ESM hook now only registers the orchestrion diagnostics-channel injection; the legacy iitm `@sentry/node/loader` entry was removed. Adds the `makeOrchestrionLoader` rollup util (import-only, delegates to `@sentry/server-utils/orchestrion/import-hook`). The legacy `makeOtelLoaders` util is kept temporarily so the framework SDKs still build until they migrate in the following PRs. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 2a913fd commit 5158f25

39 files changed

Lines changed: 136 additions & 650 deletions

File tree

MIGRATION.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ Affected SDKs: `@sentry/cloudflare`.
304304

305305
- The internal, deprecated `addAutoIpAddressToUser` export was removed.
306306
- The `createSpanEnvelope` function and the `SpanEnvelope` / `SpanItem` types were removed. They existed only to send standalone (v1) spans as their own segment envelope, which the SDK no longer does. Standalone spans are gone; spans are sent either on their transaction or, with span streaming, as streamed spans (`StreamedSpanEnvelope`).
307+
- The `disableInstrumentationWarnings` option and the `MissingInstrumentationContext` type were removed. Now that instrumentation is channel-based, the SDK can no longer detect the "you imported a framework before `Sentry.init()`" case, so the warning it gated and the context it attached no longer exist.
307308
- The deprecated `sendDefaultPii` option was removed. Use [`dataCollection`](#senddefaultpii-is-replaced-by-datacollection) instead.
308309
- The `_experiments.enableMetrics` and `_experiments.beforeSendMetric` options were removed, use the top-level `enableMetrics` and `beforeSendMetric` options instead.
309310

@@ -396,6 +397,8 @@ Sentry.init({
396397
- The deprecated `prismaInstrumentation` option was removed. It was no longer used, as Prisma works out of the box.
397398
- The `registerEsmLoaderHooks` option was removed. All instrumentation is now channel-based (via `@sentry/server-utils`), so the SDK no longer registers `import-in-the-middle` ESM loader hooks and the option no longer had any effect.
398399
- The deprecated `SentryHttpInstrumentation` and `SentryNodeFetchInstrumentation` exports were removed. Use `instrumentHttpOutgoingRequests()` and the `nativeNodeFetchIntegration` respectively.
400+
- The `generateInstrumentOnce` export was removed (from `@sentry/node` and the framework SDKs that re-exported it). It wrapped OpenTelemetry's `registerInstrumentations` and is no longer needed now that instrumentation is channel-based.
401+
- The `@sentry/node/loader` entry point was removed. It only re-exported the `import-in-the-middle` ESM `load`/`resolve` hooks, which are unused now that Node's `--loader` flag is obsolete (minimum Node is 20.19.0) and instrumentation is channel-based. Use `node --import @sentry/node/import` instead.
399402
- (Fastify) The deprecated `setShouldHandleError` method was removed.
400403
- (AWS Lambda) The deprecated `disableAwsContextPropagation` option was removed. It no longer had any effect.
401404
- (AWS Lambda) The deprecated `startTrace` option was removed. It no longer had any effect; to disable tracing, set `tracesSampleRate` to `0`.

dev-packages/e2e-tests/test-applications/node-express-incorrect-instrumentation/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

dev-packages/e2e-tests/test-applications/node-express-incorrect-instrumentation/package.json

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

dev-packages/e2e-tests/test-applications/node-express-incorrect-instrumentation/playwright.config.mjs

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

dev-packages/e2e-tests/test-applications/node-express-incorrect-instrumentation/src/app.ts

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

dev-packages/e2e-tests/test-applications/node-express-incorrect-instrumentation/start-event-proxy.mjs

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

dev-packages/e2e-tests/test-applications/node-express-incorrect-instrumentation/tests/instrumentation.test.ts

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

dev-packages/e2e-tests/test-applications/node-express-incorrect-instrumentation/tsconfig.json

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import '@sentry/server-utils/orchestrion/import-hook';

dev-packages/rollup-utils/npmHelpers.mjs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,3 +282,53 @@ export function makeOtelLoaders(outputFolder, hookVariant, options = {}) {
282282
},
283283
]);
284284
}
285+
286+
/**
287+
* Emits the `@sentry/<framework>/import` entry (`build/import-hook.mjs`) as part of the rollup build,
288+
* used as `node --import @sentry/<framework>/import app.js`. The generated hook imports
289+
* `@sentry/server-utils/orchestrion/import-hook`, which registers the orchestrion
290+
* diagnostics-channel injection, so the consuming package must declare `@sentry/server-utils` as a
291+
* dependency.
292+
*
293+
* @param {string} outputFolder Build output folder.
294+
*/
295+
export function makeOrchestrionLoader(outputFolder) {
296+
const expectedImportHookLocation = `${outputFolder}/import-hook.mjs`;
297+
const foundImportHookExport = Object.keys(packageDotJSON.exports ?? {}).some(key => {
298+
return packageDotJSON?.exports?.[key]?.import?.default === expectedImportHookLocation;
299+
});
300+
if (!foundImportHookExport) {
301+
throw new Error(
302+
`You used the makeOrchestrionLoader() rollup utility without specifying the import hook inside \`exports[something].import.default\`. Please add "${expectedImportHookLocation}" as a value there (maybe check for typos - it needs to be "${expectedImportHookLocation}" exactly).`,
303+
);
304+
}
305+
306+
const requiredDep = '@sentry/server-utils';
307+
const foundRequiredDep =
308+
Object.keys(packageDotJSON.dependencies ?? {}).some(key => {
309+
return key === requiredDep;
310+
}) ||
311+
Object.keys(packageDotJSON.devDependencies ?? {}).some(key => {
312+
return key === requiredDep;
313+
});
314+
315+
if (!foundRequiredDep) {
316+
throw new Error(
317+
`You used the makeOrchestrionLoader() rollup utility but didn't specify the "${requiredDep}" dependency in ${path.resolve(
318+
process.cwd(),
319+
'package.json',
320+
)}. Please add it to the dependencies.`,
321+
);
322+
}
323+
324+
return defineConfig([
325+
{
326+
input: path.join(__dirname, 'code', 'importHookTemplate.js'),
327+
external: /.*/,
328+
output: {
329+
format: 'esm',
330+
file: path.join(outputFolder, 'import-hook.mjs'),
331+
},
332+
},
333+
]);
334+
}

0 commit comments

Comments
 (0)