diff --git a/docs/migration/draft-v9-migration-guide.md b/docs/migration/draft-v9-migration-guide.md index 7115fe6133d7..fb62a6635e0d 100644 --- a/docs/migration/draft-v9-migration-guide.md +++ b/docs/migration/draft-v9-migration-guide.md @@ -106,5 +106,6 @@ - Deprecated `processThreadBreadcrumbIntegration` in favor of `childProcessIntegration`. Functionally they are the same. - Deprecated `nestIntegration`. Use the NestJS SDK (`@sentry/nestjs`) instead. - Deprecated `setupNestErrorHandler`. Use the NestJS SDK (`@sentry/nestjs`) instead. +- Deprecated `addOpenTelemetryInstrumentation`. Use the `openTelemetryInstrumentations` option in `Sentry.init()` or your custom Sentry Client instead. - Deprecated `registerEsmLoaderHooks.include` and `registerEsmLoaderHooks.exclude`. Set `onlyIncludeInstrumentedModules: true` instead. - `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. diff --git a/packages/astro/src/index.server.ts b/packages/astro/src/index.server.ts index 922fdd15dce1..85603431379b 100644 --- a/packages/astro/src/index.server.ts +++ b/packages/astro/src/index.server.ts @@ -11,6 +11,7 @@ export { addBreadcrumb, addEventProcessor, addIntegration, + // eslint-disable-next-line deprecation/deprecation addOpenTelemetryInstrumentation, // eslint-disable-next-line deprecation/deprecation addRequestDataToEvent, diff --git a/packages/aws-serverless/package.json b/packages/aws-serverless/package.json index 31204042e187..5c3b049bb0ec 100644 --- a/packages/aws-serverless/package.json +++ b/packages/aws-serverless/package.json @@ -64,6 +64,7 @@ "access": "public" }, "dependencies": { + "@opentelemetry/instrumentation": "^0.54.0", "@opentelemetry/instrumentation-aws-lambda": "0.44.0", "@opentelemetry/instrumentation-aws-sdk": "0.45.0", "@sentry/core": "8.41.0", diff --git a/packages/aws-serverless/src/index.ts b/packages/aws-serverless/src/index.ts index 369e8824a3b9..6063c0c2f93d 100644 --- a/packages/aws-serverless/src/index.ts +++ b/packages/aws-serverless/src/index.ts @@ -120,6 +120,7 @@ export { spanToTraceHeader, spanToBaggageHeader, trpcMiddleware, + // eslint-disable-next-line deprecation/deprecation addOpenTelemetryInstrumentation, zodErrorsIntegration, profiler, diff --git a/packages/aws-serverless/src/integration/aws.ts b/packages/aws-serverless/src/integration/aws.ts index bfbe16bac16c..f08513e1a342 100644 --- a/packages/aws-serverless/src/integration/aws.ts +++ b/packages/aws-serverless/src/integration/aws.ts @@ -1,24 +1,23 @@ +import { registerInstrumentations } from '@opentelemetry/instrumentation'; import { AwsInstrumentation } from '@opentelemetry/instrumentation-aws-sdk'; import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, defineIntegration } from '@sentry/core'; -import { addOpenTelemetryInstrumentation } from '@sentry/node'; -import type { IntegrationFn } from '@sentry/types'; -const _awsIntegration = (() => { +/** + * Instrumentation for aws-sdk package + */ +export const awsIntegration = defineIntegration(() => { return { name: 'Aws', setupOnce() { - addOpenTelemetryInstrumentation( - new AwsInstrumentation({ - preRequestHook(span) { - span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, 'auto.otel.aws'); - }, - }), - ); + registerInstrumentations({ + instrumentations: [ + new AwsInstrumentation({ + preRequestHook(span) { + span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, 'auto.otel.aws'); + }, + }), + ], + }); }, }; -}) satisfies IntegrationFn; - -/** - * Instrumentation for aws-sdk package - */ -export const awsIntegration = defineIntegration(_awsIntegration); +}); diff --git a/packages/bun/src/index.ts b/packages/bun/src/index.ts index 02718da1153c..276c4ff38c4b 100644 --- a/packages/bun/src/index.ts +++ b/packages/bun/src/index.ts @@ -140,6 +140,7 @@ export { spanToTraceHeader, spanToBaggageHeader, trpcMiddleware, + // eslint-disable-next-line deprecation/deprecation addOpenTelemetryInstrumentation, zodErrorsIntegration, profiler, diff --git a/packages/google-cloud-serverless/src/index.ts b/packages/google-cloud-serverless/src/index.ts index 415062811fb8..64d57ec530b3 100644 --- a/packages/google-cloud-serverless/src/index.ts +++ b/packages/google-cloud-serverless/src/index.ts @@ -117,6 +117,7 @@ export { spanToTraceHeader, spanToBaggageHeader, trpcMiddleware, + // eslint-disable-next-line deprecation/deprecation addOpenTelemetryInstrumentation, zodErrorsIntegration, profiler, diff --git a/packages/node/src/index.ts b/packages/node/src/index.ts index df6cce5383a3..69180bd18c88 100644 --- a/packages/node/src/index.ts +++ b/packages/node/src/index.ts @@ -61,6 +61,7 @@ export type { NodeOptions } from './types'; export { addRequestDataToEvent, DEFAULT_USER_INCLUDES, extractRequestData } from '@sentry/core'; export { + // eslint-disable-next-line deprecation/deprecation addOpenTelemetryInstrumentation, // These are custom variants that need to be used instead of the core one // As they have slightly different implementations diff --git a/packages/node/src/integrations/node-fetch.ts b/packages/node/src/integrations/node-fetch.ts index f166772ec8b4..827f11561f0d 100644 --- a/packages/node/src/integrations/node-fetch.ts +++ b/packages/node/src/integrations/node-fetch.ts @@ -1,9 +1,10 @@ +import { registerInstrumentations } from '@opentelemetry/instrumentation'; import type { UndiciRequest, UndiciResponse } from '@opentelemetry/instrumentation-undici'; import { UndiciInstrumentation } from '@opentelemetry/instrumentation-undici'; import { LRUMap, getClient, getTraceData } from '@sentry/core'; import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, addBreadcrumb, defineIntegration, hasTracingEnabled } from '@sentry/core'; import { getBreadcrumbLogLevelFromHttpStatusCode, getSanitizedUrlString, parseUrl } from '@sentry/core'; -import { addOpenTelemetryInstrumentation, shouldPropagateTraceForUrl } from '@sentry/opentelemetry'; +import { shouldPropagateTraceForUrl } from '@sentry/opentelemetry'; import type { IntegrationFn, SanitizedRequestData } from '@sentry/types'; interface NodeFetchOptions { @@ -74,7 +75,7 @@ const _nativeNodeFetchIntegration = ((options: NodeFetchOptions = {}) => { }, }); - addOpenTelemetryInstrumentation(instrumentation); + registerInstrumentations({ instrumentations: [instrumentation] }); }, }; }) satisfies IntegrationFn; diff --git a/packages/node/src/otel/instrument.ts b/packages/node/src/otel/instrument.ts index 6db677a3956c..c5bd7500a739 100644 --- a/packages/node/src/otel/instrument.ts +++ b/packages/node/src/otel/instrument.ts @@ -1,5 +1,4 @@ -import type { Instrumentation } from '@opentelemetry/instrumentation'; -import { addOpenTelemetryInstrumentation } from '@sentry/opentelemetry'; +import { type Instrumentation, registerInstrumentations } from '@opentelemetry/instrumentation'; /** Exported only for tests. */ export const INSTRUMENTED: Record = {}; @@ -26,7 +25,9 @@ export function generateInstrumentOnce( const instrumentation = creator(options); INSTRUMENTED[name] = instrumentation; - addOpenTelemetryInstrumentation(instrumentation); + registerInstrumentations({ + instrumentations: [instrumentation], + }); }, { id: name }, ); diff --git a/packages/opentelemetry/src/index.ts b/packages/opentelemetry/src/index.ts index d34e7a98c7b9..30228d0dd763 100644 --- a/packages/opentelemetry/src/index.ts +++ b/packages/opentelemetry/src/index.ts @@ -58,6 +58,7 @@ export { export { openTelemetrySetupCheck } from './utils/setupCheck'; +// eslint-disable-next-line deprecation/deprecation export { addOpenTelemetryInstrumentation } from './instrumentation'; // Legacy diff --git a/packages/opentelemetry/src/instrumentation.ts b/packages/opentelemetry/src/instrumentation.ts index 8dd20eac7115..979282d0e467 100644 --- a/packages/opentelemetry/src/instrumentation.ts +++ b/packages/opentelemetry/src/instrumentation.ts @@ -4,6 +4,9 @@ import { registerInstrumentations } from '@opentelemetry/instrumentation'; /** * This method takes an OpenTelemetry instrumentation or * array of instrumentations and registers them with OpenTelemetry. + * + * @deprecated This method will be removed in the next major version of the SDK. + * Use the `openTelemetryInstrumentations` option in `Sentry.init()` or your custom Sentry Client instead. */ export function addOpenTelemetryInstrumentation(...instrumentations: Instrumentation[]): void { registerInstrumentations({ diff --git a/packages/remix/src/index.server.ts b/packages/remix/src/index.server.ts index 3e0c9b4da968..3fe8c6ef8538 100644 --- a/packages/remix/src/index.server.ts +++ b/packages/remix/src/index.server.ts @@ -16,6 +16,7 @@ export { addBreadcrumb, addEventProcessor, addIntegration, + // eslint-disable-next-line deprecation/deprecation addOpenTelemetryInstrumentation, // eslint-disable-next-line deprecation/deprecation addRequestDataToEvent, diff --git a/packages/solidstart/src/server/index.ts b/packages/solidstart/src/server/index.ts index d709a373e501..6ff657695081 100644 --- a/packages/solidstart/src/server/index.ts +++ b/packages/solidstart/src/server/index.ts @@ -7,6 +7,7 @@ export { addBreadcrumb, addEventProcessor, addIntegration, + // eslint-disable-next-line deprecation/deprecation addOpenTelemetryInstrumentation, // eslint-disable-next-line deprecation/deprecation addRequestDataToEvent, diff --git a/packages/sveltekit/src/server/index.ts b/packages/sveltekit/src/server/index.ts index 4247dd46ff7a..f1c00d2f5e3a 100644 --- a/packages/sveltekit/src/server/index.ts +++ b/packages/sveltekit/src/server/index.ts @@ -7,6 +7,7 @@ export { addBreadcrumb, addEventProcessor, addIntegration, + // eslint-disable-next-line deprecation/deprecation addOpenTelemetryInstrumentation, // eslint-disable-next-line deprecation/deprecation addRequestDataToEvent,