Skip to content

Commit cef6986

Browse files
authored
feat(otel): Upgrade @opentelemetry/semantic-conventions to 1.26.0 (#13631)
resolves #13627 In 1.26.0 otel-js has updated the deprecations for the attributes based on the new changes to semantic conventions. They also changed the name of some exports, for example: `SEMATTRS_HTTP_ROUTE` -> `ATTR_HTTP_ROUTE`. Some exports names were not able to be changed because they are imported from a subpath export @opentelemetry/semantic-conventions/incubating. This subpath breaks some bundling setups, so we are unable to use it.
1 parent 017e8f9 commit cef6986

19 files changed

+133
-66
lines changed

packages/nextjs/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
},
7070
"dependencies": {
7171
"@opentelemetry/instrumentation-http": "0.53.0",
72-
"@opentelemetry/semantic-conventions": "^1.25.1",
72+
"@opentelemetry/semantic-conventions": "^1.27.0",
7373
"@rollup/plugin-commonjs": "26.0.1",
7474
"@sentry/core": "8.29.0",
7575
"@sentry/node": "8.29.0",

packages/nextjs/src/server/index.ts

+15-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ import { getDefaultIntegrations, init as nodeInit } from '@sentry/node';
1010
import type { NodeClient, NodeOptions } from '@sentry/node';
1111
import { GLOBAL_OBJ, logger } from '@sentry/utils';
1212

13-
import { SEMATTRS_HTTP_METHOD, SEMATTRS_HTTP_ROUTE, SEMATTRS_HTTP_TARGET } from '@opentelemetry/semantic-conventions';
13+
import {
14+
ATTR_HTTP_REQUEST_METHOD,
15+
ATTR_HTTP_ROUTE,
16+
SEMATTRS_HTTP_METHOD,
17+
SEMATTRS_HTTP_TARGET,
18+
} from '@opentelemetry/semantic-conventions';
1419
import type { EventProcessor } from '@sentry/types';
1520
import { DEBUG_BUILD } from '../common/debug-build';
1621
import { devErrorSymbolicationEventProcessor } from '../common/devErrorSymbolicationEventProcessor';
@@ -150,8 +155,11 @@ export function init(options: NodeOptions): NodeClient | undefined {
150155
// because we didn't get the chance to do `suppressTracing`, since this happens outside of userland.
151156
// We need to drop these spans.
152157
if (
158+
// eslint-disable-next-line deprecation/deprecation
153159
typeof spanAttributes[SEMATTRS_HTTP_TARGET] === 'string' &&
160+
// eslint-disable-next-line deprecation/deprecation
154161
spanAttributes[SEMATTRS_HTTP_TARGET].includes('sentry_key') &&
162+
// eslint-disable-next-line deprecation/deprecation
155163
spanAttributes[SEMATTRS_HTTP_TARGET].includes('sentry_client')
156164
) {
157165
samplingDecision.decision = false;
@@ -168,8 +176,12 @@ export function init(options: NodeOptions): NodeClient | undefined {
168176
const rootSpanAttributes = spanToJSON(rootSpan).data;
169177

170178
// Only hoist the http.route attribute if the transaction doesn't already have it
171-
if (rootSpanAttributes?.[SEMATTRS_HTTP_METHOD] && !rootSpanAttributes?.[SEMATTRS_HTTP_ROUTE]) {
172-
rootSpan.setAttribute(SEMATTRS_HTTP_ROUTE, spanAttributes['next.route']);
179+
if (
180+
// eslint-disable-next-line deprecation/deprecation
181+
(rootSpanAttributes?.[ATTR_HTTP_REQUEST_METHOD] || rootSpanAttributes?.[SEMATTRS_HTTP_METHOD]) &&
182+
!rootSpanAttributes?.[ATTR_HTTP_ROUTE]
183+
) {
184+
rootSpan.setAttribute(ATTR_HTTP_ROUTE, spanAttributes['next.route']);
173185
}
174186
}
175187

packages/node/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@
8787
"@opentelemetry/instrumentation-pg": "0.44.0",
8888
"@opentelemetry/instrumentation-redis-4": "0.42.0",
8989
"@opentelemetry/instrumentation-undici": "0.6.0",
90-
"@opentelemetry/resources": "^1.25.1",
91-
"@opentelemetry/sdk-trace-base": "^1.25.1",
92-
"@opentelemetry/semantic-conventions": "^1.25.1",
90+
"@opentelemetry/resources": "^1.26.0",
91+
"@opentelemetry/sdk-trace-base": "^1.26.0",
92+
"@opentelemetry/semantic-conventions": "^1.27.0",
9393
"@prisma/instrumentation": "5.19.1",
9494
"@sentry/core": "8.29.0",
9595
"@sentry/opentelemetry": "8.29.0",

packages/node/src/integrations/tracing/koa.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { KoaInstrumentation } from '@opentelemetry/instrumentation-koa';
2-
import { SEMATTRS_HTTP_ROUTE } from '@opentelemetry/semantic-conventions';
2+
import { ATTR_HTTP_ROUTE } from '@opentelemetry/semantic-conventions';
33
import {
44
SEMANTIC_ATTRIBUTE_SENTRY_OP,
55
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
@@ -29,7 +29,7 @@ export const instrumentKoa = generateInstrumentOnce(
2929
return;
3030
}
3131
const attributes = spanToJSON(span).data;
32-
const route = attributes && attributes[SEMATTRS_HTTP_ROUTE];
32+
const route = attributes && attributes[ATTR_HTTP_ROUTE];
3333
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
3434
const method: string = info?.context?.request?.method?.toUpperCase() || 'GET';
3535
if (route) {

packages/node/src/sdk/initOtel.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { DiagLogLevel, diag } from '@opentelemetry/api';
33
import { Resource } from '@opentelemetry/resources';
44
import { BasicTracerProvider } from '@opentelemetry/sdk-trace-base';
55
import {
6-
SEMRESATTRS_SERVICE_NAME,
6+
ATTR_SERVICE_NAME,
7+
ATTR_SERVICE_VERSION,
78
SEMRESATTRS_SERVICE_NAMESPACE,
8-
SEMRESATTRS_SERVICE_VERSION,
99
} from '@opentelemetry/semantic-conventions';
1010
import { SDK_VERSION } from '@sentry/core';
1111
import { SentryPropagator, SentrySampler, SentrySpanProcessor } from '@sentry/opentelemetry';
@@ -130,9 +130,10 @@ export function setupOtel(client: NodeClient): BasicTracerProvider {
130130
const provider = new BasicTracerProvider({
131131
sampler: new SentrySampler(client),
132132
resource: new Resource({
133-
[SEMRESATTRS_SERVICE_NAME]: 'node',
133+
[ATTR_SERVICE_NAME]: 'node',
134+
// eslint-disable-next-line deprecation/deprecation
134135
[SEMRESATTRS_SERVICE_NAMESPACE]: 'sentry',
135-
[SEMRESATTRS_SERVICE_VERSION]: SDK_VERSION,
136+
[ATTR_SERVICE_VERSION]: SDK_VERSION,
136137
}),
137138
forceFlushTimeoutMillis: 500,
138139
});

packages/opentelemetry/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@
4747
"@opentelemetry/api": "^1.9.0",
4848
"@opentelemetry/core": "^1.25.1",
4949
"@opentelemetry/instrumentation": "^0.53.0",
50-
"@opentelemetry/sdk-trace-base": "^1.25.1",
51-
"@opentelemetry/semantic-conventions": "^1.25.1"
50+
"@opentelemetry/sdk-trace-base": "^1.26.0",
51+
"@opentelemetry/semantic-conventions": "^1.27.0"
5252
},
5353
"devDependencies": {
5454
"@opentelemetry/api": "^1.9.0",
5555
"@opentelemetry/context-async-hooks": "^1.25.1",
5656
"@opentelemetry/core": "^1.25.1",
57-
"@opentelemetry/sdk-trace-base": "^1.25.1",
58-
"@opentelemetry/semantic-conventions": "^1.25.1"
57+
"@opentelemetry/sdk-trace-base": "^1.26.0",
58+
"@opentelemetry/semantic-conventions": "^1.27.0"
5959
},
6060
"scripts": {
6161
"build": "run-p build:transpile build:types",

packages/opentelemetry/src/propagator.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ import { INVALID_TRACEID } from '@opentelemetry/api';
33
import { context } from '@opentelemetry/api';
44
import { propagation, trace } from '@opentelemetry/api';
55
import { W3CBaggagePropagator, isTracingSuppressed } from '@opentelemetry/core';
6-
import { SEMATTRS_HTTP_URL } from '@opentelemetry/semantic-conventions';
6+
import { ATTR_URL_FULL, SEMATTRS_HTTP_URL } from '@opentelemetry/semantic-conventions';
77
import type { continueTrace } from '@sentry/core';
8-
import { SEMANTIC_ATTRIBUTE_URL_FULL } from '@sentry/core';
98
import { hasTracingEnabled } from '@sentry/core';
109
import { getRootSpan } from '@sentry/core';
1110
import { spanToJSON } from '@sentry/core';
@@ -294,7 +293,9 @@ function getExistingBaggage(carrier: unknown): string | undefined {
294293
*/
295294
function getCurrentURL(span: Span): string | undefined {
296295
const spanData = spanToJSON(span).data;
297-
const urlAttribute = spanData?.[SEMATTRS_HTTP_URL] || spanData?.[SEMANTIC_ATTRIBUTE_URL_FULL];
296+
// `ATTR_URL_FULL` is the new attribute, but we still support the old one, `SEMATTRS_HTTP_URL`, for now.
297+
// eslint-disable-next-line deprecation/deprecation
298+
const urlAttribute = spanData?.[SEMATTRS_HTTP_URL] || spanData?.[ATTR_URL_FULL];
298299
if (urlAttribute) {
299300
return urlAttribute;
300301
}

packages/opentelemetry/src/sampler.ts

+15-10
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,21 @@ import { TraceState } from '@opentelemetry/core';
55
import type { Sampler, SamplingResult } from '@opentelemetry/sdk-trace-base';
66
import { SamplingDecision } from '@opentelemetry/sdk-trace-base';
77
import {
8-
SEMANTIC_ATTRIBUTE_HTTP_REQUEST_METHOD,
98
SEMANTIC_ATTRIBUTE_SENTRY_OP,
109
SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE,
11-
SEMANTIC_ATTRIBUTE_URL_FULL,
1210
hasTracingEnabled,
1311
sampleSpan,
1412
} from '@sentry/core';
1513
import type { Client, SpanAttributes } from '@sentry/types';
1614
import { logger } from '@sentry/utils';
1715
import { SENTRY_TRACE_STATE_SAMPLED_NOT_RECORDING, SENTRY_TRACE_STATE_URL } from './constants';
1816

19-
import { SEMATTRS_HTTP_METHOD, SEMATTRS_HTTP_URL } from '@opentelemetry/semantic-conventions';
17+
import {
18+
ATTR_HTTP_REQUEST_METHOD,
19+
ATTR_URL_FULL,
20+
SEMATTRS_HTTP_METHOD,
21+
SEMATTRS_HTTP_URL,
22+
} from '@opentelemetry/semantic-conventions';
2023
import { DEBUG_BUILD } from './debug-build';
2124
import { getPropagationContextFromSpan } from './propagator';
2225
import { getSamplingDecision } from './utils/getSamplingDecision';
@@ -52,13 +55,13 @@ export class SentrySampler implements Sampler {
5255
return wrapSamplingDecision({ decision: undefined, context, spanAttributes });
5356
}
5457

58+
// `ATTR_HTTP_REQUEST_METHOD` is the new attribute, but we still support the old one, `SEMATTRS_HTTP_METHOD`, for now.
59+
// eslint-disable-next-line deprecation/deprecation
60+
const maybeSpanHttpMethod = spanAttributes[SEMATTRS_HTTP_METHOD] || spanAttributes[ATTR_HTTP_REQUEST_METHOD];
61+
5562
// If we have a http.client span that has no local parent, we never want to sample it
5663
// but we want to leave downstream sampling decisions up to the server
57-
if (
58-
spanKind === SpanKind.CLIENT &&
59-
(spanAttributes[SEMATTRS_HTTP_METHOD] || spanAttributes[SEMANTIC_ATTRIBUTE_HTTP_REQUEST_METHOD]) &&
60-
(!parentSpan || parentContext?.isRemote)
61-
) {
64+
if (spanKind === SpanKind.CLIENT && maybeSpanHttpMethod && (!parentSpan || parentContext?.isRemote)) {
6265
return wrapSamplingDecision({ decision: undefined, context, spanAttributes });
6366
}
6467

@@ -109,7 +112,7 @@ export class SentrySampler implements Sampler {
109112
[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE]: sampleRate,
110113
};
111114

112-
const method = `${spanAttributes[SEMATTRS_HTTP_METHOD]}`.toUpperCase();
115+
const method = `${maybeSpanHttpMethod}`.toUpperCase();
113116
if (method === 'OPTIONS' || method === 'HEAD') {
114117
DEBUG_BUILD && logger.log(`[Tracing] Not sampling span because HTTP method is '${method}' for ${spanName}`);
115118

@@ -198,7 +201,9 @@ function getBaseTraceState(context: Context, spanAttributes: SpanAttributes): Tr
198201
let traceState = parentContext?.traceState || new TraceState();
199202

200203
// We always keep the URL on the trace state, so we can access it in the propagator
201-
const url = spanAttributes[SEMATTRS_HTTP_URL] || spanAttributes[SEMANTIC_ATTRIBUTE_URL_FULL];
204+
// `ATTR_URL_FULL` is the new attribute, but we still support the old one, `ATTR_HTTP_URL`, for now.
205+
// eslint-disable-next-line deprecation/deprecation
206+
const url = spanAttributes[SEMATTRS_HTTP_URL] || spanAttributes[ATTR_URL_FULL];
202207
if (url && typeof url === 'string') {
203208
traceState = traceState.set(SENTRY_TRACE_STATE_URL, url);
204209
}

packages/opentelemetry/src/spanExporter.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Span } from '@opentelemetry/api';
22
import { SpanKind } from '@opentelemetry/api';
33
import type { ReadableSpan } from '@opentelemetry/sdk-trace-base';
4-
import { SEMATTRS_HTTP_STATUS_CODE } from '@opentelemetry/semantic-conventions';
4+
import { ATTR_HTTP_RESPONSE_STATUS_CODE, SEMATTRS_HTTP_STATUS_CODE } from '@opentelemetry/semantic-conventions';
55
import {
66
captureEvent,
77
getCapturedScopesOnSpan,
@@ -358,9 +358,10 @@ function getData(span: ReadableSpan): Record<string, unknown> {
358358
data['otel.kind'] = SpanKind[span.kind];
359359
}
360360

361-
if (attributes[SEMATTRS_HTTP_STATUS_CODE]) {
362-
const statusCode = attributes[SEMATTRS_HTTP_STATUS_CODE] as string;
363-
data['http.response.status_code'] = statusCode;
361+
// eslint-disable-next-line deprecation/deprecation
362+
const maybeHttpStatusCodeAttribute = attributes[SEMATTRS_HTTP_STATUS_CODE];
363+
if (maybeHttpStatusCodeAttribute) {
364+
data[ATTR_HTTP_RESPONSE_STATUS_CODE] = maybeHttpStatusCodeAttribute as string;
364365
}
365366

366367
const requestData = getRequestSpanData(span);

packages/opentelemetry/src/utils/getRequestSpanData.ts

+18-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import type { Span } from '@opentelemetry/api';
22
import type { ReadableSpan } from '@opentelemetry/sdk-trace-base';
3-
import { SEMATTRS_HTTP_METHOD, SEMATTRS_HTTP_URL } from '@opentelemetry/semantic-conventions';
3+
import {
4+
ATTR_HTTP_REQUEST_METHOD,
5+
ATTR_URL_FULL,
6+
SEMATTRS_HTTP_METHOD,
7+
SEMATTRS_HTTP_URL,
8+
} from '@opentelemetry/semantic-conventions';
49
import type { SanitizedRequestData } from '@sentry/types';
510
import { getSanitizedUrlString, parseUrl } from '@sentry/utils';
611

@@ -15,9 +20,17 @@ export function getRequestSpanData(span: Span | ReadableSpan): Partial<Sanitized
1520
return {};
1621
}
1722

23+
// eslint-disable-next-line deprecation/deprecation
24+
const maybeUrlAttribute = (span.attributes[ATTR_URL_FULL] || span.attributes[SEMATTRS_HTTP_URL]) as
25+
| string
26+
| undefined;
27+
1828
const data: Partial<SanitizedRequestData> = {
19-
url: span.attributes[SEMATTRS_HTTP_URL] as string | undefined,
20-
'http.method': span.attributes[SEMATTRS_HTTP_METHOD] as string | undefined,
29+
url: maybeUrlAttribute,
30+
// eslint-disable-next-line deprecation/deprecation
31+
'http.method': (span.attributes[ATTR_HTTP_REQUEST_METHOD] || span.attributes[SEMATTRS_HTTP_METHOD]) as
32+
| string
33+
| undefined,
2134
};
2235

2336
// Default to GET if URL is set but method is not
@@ -26,9 +39,8 @@ export function getRequestSpanData(span: Span | ReadableSpan): Partial<Sanitized
2639
}
2740

2841
try {
29-
const urlStr = span.attributes[SEMATTRS_HTTP_URL];
30-
if (typeof urlStr === 'string') {
31-
const url = parseUrl(urlStr);
42+
if (typeof maybeUrlAttribute === 'string') {
43+
const url = parseUrl(maybeUrlAttribute);
3244

3345
data.url = getSanitizedUrlString(url);
3446

packages/opentelemetry/src/utils/isSentryRequest.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { SEMATTRS_HTTP_URL } from '@opentelemetry/semantic-conventions';
2-
import { SEMANTIC_ATTRIBUTE_URL_FULL, getClient, isSentryRequestUrl } from '@sentry/core';
1+
import { ATTR_URL_FULL, SEMATTRS_HTTP_URL } from '@opentelemetry/semantic-conventions';
2+
import { getClient, isSentryRequestUrl } from '@sentry/core';
33

44
import type { AbstractSpan } from '../types';
55
import { spanHasAttributes } from './spanTypes';
@@ -16,7 +16,9 @@ export function isSentryRequestSpan(span: AbstractSpan): boolean {
1616

1717
const { attributes } = span;
1818

19-
const httpUrl = attributes[SEMATTRS_HTTP_URL] || attributes[SEMANTIC_ATTRIBUTE_URL_FULL];
19+
// `ATTR_URL_FULL` is the new attribute, but we still support the old one, `ATTR_HTTP_URL`, for now.
20+
// eslint-disable-next-line deprecation/deprecation
21+
const httpUrl = attributes[SEMATTRS_HTTP_URL] || attributes[ATTR_URL_FULL];
2022

2123
if (!httpUrl) {
2224
return false;

packages/opentelemetry/src/utils/mapStatus.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { SpanStatusCode } from '@opentelemetry/api';
2-
import { SEMATTRS_HTTP_STATUS_CODE, SEMATTRS_RPC_GRPC_STATUS_CODE } from '@opentelemetry/semantic-conventions';
2+
import {
3+
ATTR_HTTP_RESPONSE_STATUS_CODE,
4+
SEMATTRS_HTTP_STATUS_CODE,
5+
SEMATTRS_RPC_GRPC_STATUS_CODE,
6+
} from '@opentelemetry/semantic-conventions';
37
import { SPAN_STATUS_ERROR, SPAN_STATUS_OK, getSpanStatusFromHttpCode } from '@sentry/core';
48
import type { SpanAttributes, SpanStatus } from '@sentry/types';
59

@@ -76,7 +80,9 @@ export function mapStatus(span: AbstractSpan): SpanStatus {
7680
function inferStatusFromAttributes(attributes: SpanAttributes): SpanStatus | undefined {
7781
// If the span status is UNSET, we try to infer it from HTTP or GRPC status codes.
7882

79-
const httpCodeAttribute = attributes[SEMATTRS_HTTP_STATUS_CODE];
83+
// eslint-disable-next-line deprecation/deprecation
84+
const httpCodeAttribute = attributes[ATTR_HTTP_RESPONSE_STATUS_CODE] || attributes[SEMATTRS_HTTP_STATUS_CODE];
85+
// eslint-disable-next-line deprecation/deprecation
8086
const grpcCodeAttribute = attributes[SEMATTRS_RPC_GRPC_STATUS_CODE];
8187

8288
const numberHttpCode =

0 commit comments

Comments
 (0)