Skip to content
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

chore: Bump otel 2.x #15518

Draft
wants to merge 11 commits into
base: develop
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"dependencies": {
"@opentelemetry/api": "^1.9.0",
"@opentelemetry/sdk-trace-node": "^1.25.1",
"@opentelemetry/sdk-trace-node": "^2.0.0",
"@sentry/node": "latest || *",
"@sentry/opentelemetry": "latest || *",
"@types/express": "4.17.17",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"test:assert": "pnpm test"
},
"dependencies": {
"@opentelemetry/sdk-node": "0.52.1",
"@opentelemetry/exporter-trace-otlp-http": "0.52.1",
"@opentelemetry/sdk-node": "0.200.0",
"@opentelemetry/exporter-trace-otlp-http": "0.200.0",
"@sentry/core": "latest || *",
"@sentry/node": "latest || *",
"@sentry/opentelemetry": "latest || *",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
"test:assert": "pnpm test"
},
"dependencies": {
"@opentelemetry/sdk-trace-node": "1.26.0",
"@opentelemetry/exporter-trace-otlp-http": "0.53.0",
"@opentelemetry/sdk-trace-node": "2.0.0",
"@opentelemetry/exporter-trace-otlp-http": "0.200.0",
"@opentelemetry/instrumentation-undici": "0.6.0",
"@opentelemetry/instrumentation-http": "0.53.0",
"@opentelemetry/instrumentation": "0.53.0",
"@opentelemetry/instrumentation-http": "0.200.0",
"@opentelemetry/instrumentation": "0.200.0",
"@sentry/core": "latest || *",
"@sentry/node": "latest || *",
"@sentry/opentelemetry": "latest || *",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"test:assert": "pnpm test"
},
"dependencies": {
"@opentelemetry/sdk-node": "0.52.1",
"@opentelemetry/exporter-trace-otlp-http": "0.52.1",
"@opentelemetry/sdk-node": "0.200.0",
"@opentelemetry/exporter-trace-otlp-http": "0.200.0",
"@sentry/core": "latest || *",
"@sentry/node": "latest || *",
"@sentry/opentelemetry": "latest || *",
Expand Down
2 changes: 1 addition & 1 deletion packages/aws-serverless/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
},
"dependencies": {
"@opentelemetry/api": "^1.9.0",
"@opentelemetry/instrumentation": "^0.57.2",
"@opentelemetry/instrumentation": "^0.200.0",
"@opentelemetry/instrumentation-aws-lambda": "0.50.3",
"@opentelemetry/instrumentation-aws-sdk": "0.49.1",
"@sentry/core": "9.10.1",
Expand Down
8 changes: 5 additions & 3 deletions packages/core/src/utils/spanUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import type {
SpanOrigin,
SpanStatus,
SpanTimeInput,
SpanContextData,
TraceContext,
} from '../types-hoist';
import type { SpanLink, SpanLinkJSON } from '../types-hoist/link';
Expand Down Expand Up @@ -145,14 +146,15 @@ export function spanToJSON(span: Span): SpanJSON {

// Handle a span from @opentelemetry/sdk-base-trace's `Span` class
if (spanIsOpenTelemetrySdkTraceBaseSpan(span)) {
const { attributes, startTime, name, endTime, parentSpanId, status, links } = span;
const { attributes, startTime, name, endTime, status, links } = span;
const parent_span_id = span.parentSpanContext?.spanId;

return {
span_id,
trace_id,
data: attributes,
description: name,
parent_span_id: parentSpanId,
parent_span_id,
start_timestamp: spanTimeInputToSeconds(startTime),
// This is [0,0] by default in OTEL, in which case we want to interpret this as no end time
timestamp: spanTimeInputToSeconds(endTime) || undefined,
Expand Down Expand Up @@ -185,7 +187,7 @@ export interface OpenTelemetrySdkTraceBaseSpan extends Span {
name: string;
status: SpanStatus;
endTime: SpanTimeInput;
parentSpanId?: string;
parentSpanContext?: SpanContextData;
links?: SpanLink[];
}

Expand Down
4 changes: 2 additions & 2 deletions packages/nestjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
},
"dependencies": {
"@opentelemetry/api": "^1.9.0",
"@opentelemetry/core": "^1.30.1",
"@opentelemetry/instrumentation": "0.57.2",
"@opentelemetry/core": "^2.0.0",
"@opentelemetry/instrumentation": "0.200.0",
"@opentelemetry/instrumentation-nestjs-core": "0.44.1",
"@opentelemetry/semantic-conventions": "^1.30.0",
"@sentry/core": "9.10.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { isWrapped } from '@opentelemetry/core';
import type { InstrumentationConfig } from '@opentelemetry/instrumentation';
import {
InstrumentationBase,
InstrumentationNodeModuleDefinition,
InstrumentationNodeModuleFile,
isWrapped,
} from '@opentelemetry/instrumentation';
import { SDK_VERSION, captureException, startSpan } from '@sentry/core';
import { getEventSpanOptions } from './helpers';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { isWrapped } from '@opentelemetry/core';
import type { InstrumentationConfig } from '@opentelemetry/instrumentation';
import {
InstrumentationBase,
InstrumentationNodeModuleDefinition,
InstrumentationNodeModuleFile,
isWrapped,
} from '@opentelemetry/instrumentation';
import type { Span } from '@sentry/core';
import {
Expand Down
12 changes: 6 additions & 6 deletions packages/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@
},
"dependencies": {
"@opentelemetry/api": "^1.9.0",
"@opentelemetry/context-async-hooks": "^1.30.1",
"@opentelemetry/core": "^1.30.1",
"@opentelemetry/instrumentation": "^0.57.2",
"@opentelemetry/context-async-hooks": "^2.0.0",
"@opentelemetry/core": "^2.0.0",
"@opentelemetry/instrumentation": "^0.200.0",
"@opentelemetry/instrumentation-amqplib": "^0.46.1",
"@opentelemetry/instrumentation-connect": "0.43.1",
"@opentelemetry/instrumentation-dataloader": "0.16.1",
Expand All @@ -78,7 +78,7 @@
"@opentelemetry/instrumentation-generic-pool": "0.43.1",
"@opentelemetry/instrumentation-graphql": "0.47.1",
"@opentelemetry/instrumentation-hapi": "0.45.2",
"@opentelemetry/instrumentation-http": "0.57.2",
"@opentelemetry/instrumentation-http": "0.200.0",
"@opentelemetry/instrumentation-ioredis": "0.47.1",
"@opentelemetry/instrumentation-kafkajs": "0.7.1",
"@opentelemetry/instrumentation-knex": "0.44.1",
Expand All @@ -92,8 +92,8 @@
"@opentelemetry/instrumentation-redis-4": "0.46.1",
"@opentelemetry/instrumentation-tedious": "0.18.1",
"@opentelemetry/instrumentation-undici": "0.10.1",
"@opentelemetry/resources": "^1.30.1",
"@opentelemetry/sdk-trace-base": "^1.30.1",
"@opentelemetry/resources": "^2.0.0",
"@opentelemetry/sdk-trace-base": "^2.0.0",
"@opentelemetry/semantic-conventions": "^1.30.0",
"@prisma/instrumentation": "6.5.0",
"@sentry/core": "9.10.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint-disable max-lines */
import { context, propagation } from '@opentelemetry/api';
import { VERSION } from '@opentelemetry/core';
import type { InstrumentationConfig } from '@opentelemetry/instrumentation';
import { InstrumentationBase, InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation';
import type { AggregationCounts, Client, RequestEventData, SanitizedRequestData, Scope } from '@sentry/core';
Expand Down Expand Up @@ -92,7 +91,7 @@ const MAX_BODY_BYTE_LENGTH = 1024 * 1024;
*/
export class SentryHttpInstrumentation extends InstrumentationBase<SentryHttpInstrumentationOptions> {
public constructor(config: SentryHttpInstrumentationOptions = {}) {
super('@sentry/instrumentation-http', VERSION, config);
super('@sentry/instrumentation-http', '2.0.0', config);
}

/** @inheritdoc */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { VERSION } from '@opentelemetry/core';
import type { InstrumentationConfig } from '@opentelemetry/instrumentation';
import { InstrumentationBase } from '@opentelemetry/instrumentation';
import type { SanitizedRequestData } from '@sentry/core';
Expand Down Expand Up @@ -56,7 +55,7 @@ export class SentryNodeFetchInstrumentation extends InstrumentationBase<SentryNo
private _propagationDecisionMap: LRUMap<string, boolean>;

public constructor(config: SentryNodeFetchInstrumentationOptions = {}) {
super('@sentry/instrumentation-node-fetch', VERSION, config);
super('@sentry/instrumentation-node-fetch', '2.0.0', config);
this._channelSubs = [];
this._propagationDecisionMap = new LRUMap<string, boolean>(100);
}
Expand Down
5 changes: 2 additions & 3 deletions packages/node/src/sdk/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,9 @@ export class NodeClient extends ServerRuntimeClient<NodeClientOptions> {
// eslint-disable-next-line jsdoc/require-jsdoc
public async flush(timeout?: number): Promise<boolean> {
const provider = this.traceProvider;
const spanProcessor = provider?.activeSpanProcessor;

if (spanProcessor) {
await spanProcessor.forceFlush();
if (provider) {
await provider.forceFlush();
}

if (this.getOptions().sendClientReports) {
Expand Down
16 changes: 9 additions & 7 deletions packages/node/src/sdk/initOtel.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import moduleModule from 'module';
import { DiagLogLevel, context, diag, propagation, trace } from '@opentelemetry/api';
import { Resource } from '@opentelemetry/resources';
import { defaultResource, resourceFromAttributes } from '@opentelemetry/resources';
import type { SpanProcessor } from '@opentelemetry/sdk-trace-base';
import { BasicTracerProvider } from '@opentelemetry/sdk-trace-base';
import {
Expand Down Expand Up @@ -112,12 +112,14 @@ export function setupOtel(client: NodeClient, options: AdditionalOpenTelemetryOp
// Create and configure NodeTracerProvider
const provider = new BasicTracerProvider({
sampler: new SentrySampler(client),
resource: new Resource({
[ATTR_SERVICE_NAME]: 'node',
// eslint-disable-next-line deprecation/deprecation
[SEMRESATTRS_SERVICE_NAMESPACE]: 'sentry',
[ATTR_SERVICE_VERSION]: SDK_VERSION,
}),
resource: defaultResource().merge(
resourceFromAttributes({
[ATTR_SERVICE_NAME]: 'node',
// eslint-disable-next-line deprecation/deprecation
[SEMRESATTRS_SERVICE_NAMESPACE]: 'sentry',
[ATTR_SERVICE_VERSION]: SDK_VERSION,
}),
),
forceFlushTimeoutMillis: 500,
spanProcessors: [
new SentrySpanProcessor({
Expand Down
2 changes: 1 addition & 1 deletion packages/node/src/utils/ensureIsWrapped.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isWrapped } from '@opentelemetry/core';
import { isWrapped } from '@opentelemetry/instrumentation';
import { consoleSandbox, getClient, getGlobalScope, hasSpansEnabled, isEnabled } from '@sentry/core';
import type { NodeClient } from '../sdk/client';
import { isCjs } from './commonjs';
Expand Down
16 changes: 8 additions & 8 deletions packages/opentelemetry/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,18 @@
},
"peerDependencies": {
"@opentelemetry/api": "^1.9.0",
"@opentelemetry/context-async-hooks": "^1.30.1",
"@opentelemetry/core": "^1.30.1",
"@opentelemetry/instrumentation": "^0.57.1",
"@opentelemetry/sdk-trace-base": "^1.30.1",
"@opentelemetry/context-async-hooks": "^2.0.0",
"@opentelemetry/core": "^2.0.0",
"@opentelemetry/instrumentation": "^0.200.0",
"@opentelemetry/sdk-trace-base": "^2.0.0",
"@opentelemetry/semantic-conventions": "^1.28.0"
},
"devDependencies": {
"@opentelemetry/api": "^1.9.0",
"@opentelemetry/context-async-hooks": "^1.30.1",
"@opentelemetry/core": "^1.30.1",
"@opentelemetry/instrumentation": "^0.57.2",
"@opentelemetry/sdk-trace-base": "^1.30.1",
"@opentelemetry/context-async-hooks": "^2.0.0",
"@opentelemetry/core": "^2.0.0",
"@opentelemetry/instrumentation": "^0.200.0",
"@opentelemetry/sdk-trace-base": "^2.0.0",
"@opentelemetry/semantic-conventions": "^1.30.0"
},
"scripts": {
Expand Down
7 changes: 3 additions & 4 deletions packages/opentelemetry/src/custom/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { OpenTelemetryClient as OpenTelemetryClientInterface } from '../typ
/* eslint-disable @typescript-eslint/no-explicit-any */

/**
* Wrap an Client class with things we need for OpenTelemetry support.
* Wrap a Client class with things we need for OpenTelemetry support.
* Make sure that the Client class passed in is non-abstract!
*
* Usage:
Expand Down Expand Up @@ -49,10 +49,9 @@ export function wrapClientClass<
*/
public async flush(timeout?: number): Promise<boolean> {
const provider = this.traceProvider;
const spanProcessor = provider?.activeSpanProcessor;

if (spanProcessor) {
await spanProcessor.forceFlush();
if (provider) {
await provider.forceFlush();
}

return super.flush(timeout);
Expand Down
7 changes: 4 additions & 3 deletions packages/opentelemetry/src/spanExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ export function createTransactionForOtelSpan(span: ReadableSpan): TransactionEve
// even if `span.parentSpanId` is set
// this is the case when we are starting a new trace, where we have a virtual span based on the propagationContext
// We only want to continue the traceId in this case, but ignore the parent span
const parent_span_id = span.parentSpanId;
const parent_span_id = span.parentSpanContext?.spanId;

const status = mapStatus(span);

Expand Down Expand Up @@ -321,8 +321,9 @@ function createAndFinishSpanForOtelSpan(node: SpanNode, spans: SpanJSON[], sentS

const span_id = span.spanContext().spanId;
const trace_id = span.spanContext().traceId;
const parent_span_id = span.parentSpanContext?.spanId;

const { attributes, startTime, endTime, parentSpanId, links } = span;
const { attributes, startTime, endTime, links } = span;

const { op, description, data, origin = 'manual' } = getSpanData(span);
const allData = {
Expand All @@ -339,7 +340,7 @@ function createAndFinishSpanForOtelSpan(node: SpanNode, spans: SpanJSON[], sentS
trace_id,
data: allData,
description,
parent_span_id: parentSpanId,
parent_span_id,
start_timestamp: spanTimeInputToSeconds(startTime),
// This is [0,0] by default in OTEL, in which case we want to interpret this as no end time
timestamp: spanTimeInputToSeconds(endTime) || undefined,
Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry/src/utils/groupSpansWithParents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function getLocalParentId(span: ReadableSpan): string | undefined {
const parentIsRemote = span.attributes[SEMANTIC_ATTRIBUTE_SENTRY_PARENT_IS_REMOTE] === true;
// If the parentId is the trace parent ID, we pretend it's undefined
// As this means the parent exists somewhere else
return !parentIsRemote ? span.parentSpanId : undefined;
return !parentIsRemote ? span.parentSpanContext?.spanId : undefined;
}

function createOrUpdateSpanNodeAndRefs(nodeMap: SpanMap, span: ReadableSpan): void {
Expand Down
6 changes: 2 additions & 4 deletions packages/opentelemetry/src/utils/spanTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,9 @@ export function spanHasName<SpanType extends AbstractSpan>(span: SpanType): span
* This is necessary because the base `Span` type does not have a kind,
* so in places where we are passed a generic span, we need to check if we want to access it.
*/
export function spanHasParentId<SpanType extends AbstractSpan>(
span: SpanType,
): span is SpanType & { parentSpanId: string } {
export function spanHasParentId<SpanType extends AbstractSpan>(span: SpanType): span is SpanType {
const castSpan = span as ReadableSpan;
return !!castSpan.parentSpanId;
return !!castSpan.parentSpanContext?.spanId;
}

/**
Expand Down
16 changes: 9 additions & 7 deletions packages/opentelemetry/test/helpers/initOtel.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DiagLogLevel, context, diag, propagation, trace } from '@opentelemetry/api';
import { AsyncLocalStorageContextManager } from '@opentelemetry/context-async-hooks';
import { Resource } from '@opentelemetry/resources';
import { defaultResource, resourceFromAttributes } from '@opentelemetry/resources';
import { BasicTracerProvider } from '@opentelemetry/sdk-trace-base';
import {
ATTR_SERVICE_NAME,
Expand Down Expand Up @@ -56,12 +56,14 @@ export function setupOtel(client: TestClientInterface): BasicTracerProvider {
// Create and configure NodeTracerProvider
const provider = new BasicTracerProvider({
sampler: new SentrySampler(client),
resource: new Resource({
[ATTR_SERVICE_NAME]: 'opentelemetry-test',
// eslint-disable-next-line deprecation/deprecation
[SEMRESATTRS_SERVICE_NAMESPACE]: 'sentry',
[ATTR_SERVICE_VERSION]: SDK_VERSION,
}),
resource: defaultResource().merge(
resourceFromAttributes({
[ATTR_SERVICE_NAME]: 'opentelemetry-test',
// eslint-disable-next-line deprecation/deprecation
[SEMRESATTRS_SERVICE_NAMESPACE]: 'sentry',
[ATTR_SERVICE_VERSION]: SDK_VERSION,
}),
),
forceFlushTimeoutMillis: 500,
spanProcessors: [new SentrySpanProcessor()],
});
Expand Down
12 changes: 12 additions & 0 deletions packages/opentelemetry/test/helpers/isSpan.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { Span } from '@opentelemetry/api';
import { INVALID_TRACEID, INVALID_SPANID, type SpanContext } from '@opentelemetry/api';

export const isSpan = (value: unknown): value is Span => {
return (
typeof value === 'object' &&
value !== null &&
'spanContext' in value &&
(value.spanContext as () => SpanContext)().traceId !== INVALID_TRACEID &&
(value.spanContext as () => SpanContext)().spanId !== INVALID_SPANID
);
};
4 changes: 2 additions & 2 deletions packages/opentelemetry/test/helpers/mockSdkInit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { getCurrentScope, getGlobalScope, getIsolationScope, flush } from '@sent
import { setOpenTelemetryContextAsyncContextStrategy } from '../../src/asyncContextStrategy';
import { clearOpenTelemetrySetupCheck } from '../../src/utils/setupCheck';
import { init as initTestClient } from './TestClient';
import type { TestClientInterface } from './TestClient';
import { initOtel } from './initOtel';
import type { OpenTelemetryClient } from '../../src/types';

const PUBLIC_DSN = 'https://username@domain/123';

Expand Down Expand Up @@ -54,7 +54,7 @@ export async function cleanupOtel(_provider?: BasicTracerProvider): Promise<void
}

export function getProvider(_provider?: BasicTracerProvider): BasicTracerProvider | undefined {
let provider = _provider || getClient<OpenTelemetryClient>()?.traceProvider || trace.getTracerProvider();
let provider = _provider || getClient<TestClientInterface>()?.traceProvider || trace.getTracerProvider();

if (provider instanceof ProxyTracerProvider) {
provider = provider.getDelegate();
Expand Down
Loading
Loading