Skip to content

feat: Deprecate addOpenTelemetryInstrumentation #14485

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/migration/draft-v9-migration-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
1 change: 1 addition & 0 deletions packages/astro/src/index.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export {
addBreadcrumb,
addEventProcessor,
addIntegration,
// eslint-disable-next-line deprecation/deprecation
addOpenTelemetryInstrumentation,
// eslint-disable-next-line deprecation/deprecation
addRequestDataToEvent,
Expand Down
1 change: 1 addition & 0 deletions packages/aws-serverless/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions packages/aws-serverless/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export {
spanToTraceHeader,
spanToBaggageHeader,
trpcMiddleware,
// eslint-disable-next-line deprecation/deprecation
addOpenTelemetryInstrumentation,
zodErrorsIntegration,
profiler,
Expand Down
31 changes: 15 additions & 16 deletions packages/aws-serverless/src/integration/aws.ts
Original file line number Diff line number Diff line change
@@ -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);
});
1 change: 1 addition & 0 deletions packages/bun/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export {
spanToTraceHeader,
spanToBaggageHeader,
trpcMiddleware,
// eslint-disable-next-line deprecation/deprecation
addOpenTelemetryInstrumentation,
zodErrorsIntegration,
profiler,
Expand Down
1 change: 1 addition & 0 deletions packages/google-cloud-serverless/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export {
spanToTraceHeader,
spanToBaggageHeader,
trpcMiddleware,
// eslint-disable-next-line deprecation/deprecation
addOpenTelemetryInstrumentation,
zodErrorsIntegration,
profiler,
Expand Down
1 change: 1 addition & 0 deletions packages/node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions packages/node/src/integrations/node-fetch.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -74,7 +75,7 @@ const _nativeNodeFetchIntegration = ((options: NodeFetchOptions = {}) => {
},
});

addOpenTelemetryInstrumentation(instrumentation);
registerInstrumentations({ instrumentations: [instrumentation] });
},
};
}) satisfies IntegrationFn;
Expand Down
7 changes: 4 additions & 3 deletions packages/node/src/otel/instrument.ts
Original file line number Diff line number Diff line change
@@ -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<string, Instrumentation> = {};
Expand All @@ -26,7 +25,9 @@ export function generateInstrumentOnce<Options = unknown>(
const instrumentation = creator(options);
INSTRUMENTED[name] = instrumentation;

addOpenTelemetryInstrumentation(instrumentation);
registerInstrumentations({
instrumentations: [instrumentation],
});
},
{ id: name },
);
Expand Down
1 change: 1 addition & 0 deletions packages/opentelemetry/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export {

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

// eslint-disable-next-line deprecation/deprecation
export { addOpenTelemetryInstrumentation } from './instrumentation';

// Legacy
Expand Down
3 changes: 3 additions & 0 deletions packages/opentelemetry/src/instrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
1 change: 1 addition & 0 deletions packages/remix/src/index.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export {
addBreadcrumb,
addEventProcessor,
addIntegration,
// eslint-disable-next-line deprecation/deprecation
addOpenTelemetryInstrumentation,
// eslint-disable-next-line deprecation/deprecation
addRequestDataToEvent,
Expand Down
1 change: 1 addition & 0 deletions packages/solidstart/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export {
addBreadcrumb,
addEventProcessor,
addIntegration,
// eslint-disable-next-line deprecation/deprecation
addOpenTelemetryInstrumentation,
// eslint-disable-next-line deprecation/deprecation
addRequestDataToEvent,
Expand Down
1 change: 1 addition & 0 deletions packages/sveltekit/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export {
addBreadcrumb,
addEventProcessor,
addIntegration,
// eslint-disable-next-line deprecation/deprecation
addOpenTelemetryInstrumentation,
// eslint-disable-next-line deprecation/deprecation
addRequestDataToEvent,
Expand Down
Loading