Skip to content

Commit 6f4d10b

Browse files
committed
ref(node): Align semantic attribute handling
Also stop clearing out sentry attributes, we don't actually want that (except for the parent sampled stuff for now).
1 parent 519aacc commit 6f4d10b

File tree

7 files changed

+65
-37
lines changed

7 files changed

+65
-37
lines changed

packages/node-experimental/test/integration/transactions.test.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ describe('Integration | Transactions', () => {
7171
otel: {
7272
attributes: {
7373
'test.outer': 'test value',
74+
'sentry.op': 'test op',
75+
'sentry.origin': 'auto.test',
76+
'sentry.source': 'task',
7477
},
7578
resource: {
7679
'service.name': 'node-experimental',
@@ -247,6 +250,9 @@ describe('Integration | Transactions', () => {
247250
otel: expect.objectContaining({
248251
attributes: {
249252
'test.outer': 'test value',
253+
'sentry.op': 'test op',
254+
'sentry.origin': 'auto.test',
255+
'sentry.source': 'task',
250256
},
251257
}),
252258
trace: {
@@ -287,6 +293,7 @@ describe('Integration | Transactions', () => {
287293
otel: expect.objectContaining({
288294
attributes: {
289295
'test.outer': 'test value b',
296+
'sentry.op': 'test op b',
290297
},
291298
}),
292299
trace: {
@@ -511,7 +518,11 @@ describe('Integration | Transactions', () => {
511518
expect.objectContaining({
512519
contexts: expect.objectContaining({
513520
otel: expect.objectContaining({
514-
attributes: {},
521+
attributes: {
522+
'sentry.op': 'test op',
523+
'sentry.origin': 'auto.test',
524+
'sentry.source': 'task',
525+
},
515526
}),
516527
trace: {
517528
data: {

packages/opentelemetry/src/semanticAttributes.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,5 @@
33
* No guarantees apply to these attributes, and the may change/disappear at any time.
44
*/
55
export const InternalSentrySemanticAttributes = {
6-
ORIGIN: 'sentry.origin',
7-
OP: 'sentry.op',
8-
SOURCE: 'sentry.source',
9-
SAMPLE_RATE: 'sentry.sample_rate',
106
PARENT_SAMPLED: 'sentry.parentSampled',
11-
BREADCRUMB_TYPE: 'sentry.breadcrumb.type',
12-
BREADCRUMB_LEVEL: 'sentry.breadcrumb.level',
13-
BREADCRUMB_EVENT_ID: 'sentry.breadcrumb.event_id',
14-
BREADCRUMB_CATEGORY: 'sentry.breadcrumb.category',
15-
BREADCRUMB_DATA: 'sentry.breadcrumb.data',
167
} as const;

packages/opentelemetry/src/spanExporter.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,14 @@ import { ExportResultCode } from '@opentelemetry/core';
44
import type { ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-base';
55
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
66
import type { Transaction } from '@sentry/core';
7-
import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core';
8-
import { SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, flush, getCurrentHub } from '@sentry/core';
7+
import {
8+
SEMANTIC_ATTRIBUTE_SENTRY_OP,
9+
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
10+
SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE,
11+
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
12+
flush,
13+
getCurrentHub,
14+
} from '@sentry/core';
915
import type { Scope, Span as SentrySpan, SpanOrigin, TransactionSource } from '@sentry/types';
1016
import { addNonEnumerableProperty, logger } from '@sentry/utils';
1117
import { startTransaction } from './custom/transaction';
@@ -128,9 +134,9 @@ function shouldCleanupSpan(span: ReadableSpan, maxStartTimeOffsetSeconds: number
128134
function parseSpan(span: ReadableSpan): { op?: string; origin?: SpanOrigin; source?: TransactionSource } {
129135
const attributes = span.attributes;
130136

131-
const origin = attributes[InternalSentrySemanticAttributes.ORIGIN] as SpanOrigin | undefined;
132-
const op = attributes[InternalSentrySemanticAttributes.OP] as string | undefined;
133-
const source = attributes[InternalSentrySemanticAttributes.SOURCE] as TransactionSource | undefined;
137+
const origin = attributes[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN] as SpanOrigin | undefined;
138+
const op = attributes[SEMANTIC_ATTRIBUTE_SENTRY_OP] as string | undefined;
139+
const source = attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE] as TransactionSource | undefined;
134140

135141
return { origin, op, source };
136142
}
@@ -256,9 +262,6 @@ function removeSentryAttributes(data: Record<string, unknown>): Record<string, u
256262

257263
/* eslint-disable @typescript-eslint/no-dynamic-delete */
258264
delete cleanedData[InternalSentrySemanticAttributes.PARENT_SAMPLED];
259-
delete cleanedData[InternalSentrySemanticAttributes.ORIGIN];
260-
delete cleanedData[InternalSentrySemanticAttributes.OP];
261-
delete cleanedData[InternalSentrySemanticAttributes.SOURCE];
262265
delete cleanedData[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE];
263266
/* eslint-enable @typescript-eslint/no-dynamic-delete */
264267

packages/opentelemetry/src/trace.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,17 @@ import type { Context, Span, SpanOptions, Tracer } from '@opentelemetry/api';
22
import { context } from '@opentelemetry/api';
33
import { SpanStatusCode, trace } from '@opentelemetry/api';
44
import { suppressTracing } from '@opentelemetry/core';
5-
import { SDK_VERSION, getClient, getCurrentScope, handleCallbackErrors } from '@sentry/core';
5+
import {
6+
SDK_VERSION,
7+
SEMANTIC_ATTRIBUTE_SENTRY_OP,
8+
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
9+
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
10+
getClient,
11+
getCurrentScope,
12+
handleCallbackErrors,
13+
} from '@sentry/core';
614
import type { Client, Scope } from '@sentry/types';
715

8-
import { InternalSentrySemanticAttributes } from './semanticAttributes';
916
import type { OpenTelemetryClient, OpenTelemetrySpanContext } from './types';
1017
import { getContextFromScope } from './utils/contextData';
1118
import { setSpanMetadata } from './utils/spanData';
@@ -132,15 +139,15 @@ function _applySentryAttributesToSpan(span: Span, options: OpenTelemetrySpanCont
132139
const { origin, op, source, metadata } = options;
133140

134141
if (origin) {
135-
span.setAttribute(InternalSentrySemanticAttributes.ORIGIN, origin);
142+
span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, origin);
136143
}
137144

138145
if (op) {
139-
span.setAttribute(InternalSentrySemanticAttributes.OP, op);
146+
span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, op);
140147
}
141148

142149
if (source) {
143-
span.setAttribute(InternalSentrySemanticAttributes.SOURCE, source);
150+
span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, source);
144151
}
145152

146153
if (metadata) {
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import type { Span } from '@opentelemetry/api';
2+
import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '@sentry/core';
23
import type { SpanOrigin } from '@sentry/types';
34

4-
import { InternalSentrySemanticAttributes } from '../semanticAttributes';
5-
65
/** Adds an origin to an OTEL Span. */
76
export function addOriginToSpan(span: Span, origin: SpanOrigin): void {
8-
span.setAttribute(InternalSentrySemanticAttributes.ORIGIN, origin);
7+
span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, origin);
98
}

packages/opentelemetry/test/integration/transactions.test.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ describe('Integration | Transactions', () => {
7373
otel: {
7474
attributes: {
7575
'test.outer': 'test value',
76+
'sentry.op': 'test op',
77+
'sentry.origin': 'auto.test',
78+
'sentry.source': 'task',
7679
},
7780
resource: {
7881
'service.name': 'opentelemetry-test',
@@ -238,6 +241,9 @@ describe('Integration | Transactions', () => {
238241
otel: expect.objectContaining({
239242
attributes: {
240243
'test.outer': 'test value',
244+
'sentry.op': 'test op',
245+
'sentry.origin': 'auto.test',
246+
'sentry.source': 'task',
241247
},
242248
}),
243249
trace: {
@@ -278,6 +284,7 @@ describe('Integration | Transactions', () => {
278284
otel: expect.objectContaining({
279285
attributes: {
280286
'test.outer': 'test value b',
287+
'sentry.op': 'test op b',
281288
},
282289
}),
283290
trace: {
@@ -353,7 +360,11 @@ describe('Integration | Transactions', () => {
353360
expect.objectContaining({
354361
contexts: expect.objectContaining({
355362
otel: expect.objectContaining({
356-
attributes: {},
363+
attributes: {
364+
'sentry.op': 'test op',
365+
'sentry.origin': 'auto.test',
366+
'sentry.source': 'task',
367+
},
357368
}),
358369
trace: {
359370
data: {

packages/opentelemetry/test/trace.test.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@ import { SpanKind } from '@opentelemetry/api';
33
import { TraceFlags, context, trace } from '@opentelemetry/api';
44
import type { ReadableSpan } from '@opentelemetry/sdk-trace-base';
55
import { Span as SpanClass } from '@opentelemetry/sdk-trace-base';
6-
import { SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, getClient, getCurrentScope } from '@sentry/core';
6+
import {
7+
SEMANTIC_ATTRIBUTE_SENTRY_OP,
8+
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
9+
SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE,
10+
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
11+
getClient,
12+
getCurrentScope,
13+
} from '@sentry/core';
714
import type { PropagationContext, Scope } from '@sentry/types';
815

9-
import { InternalSentrySemanticAttributes } from '../src/semanticAttributes';
1016
import { startInactiveSpan, startSpan, startSpanManual } from '../src/trace';
1117
import type { AbstractSpan } from '../src/types';
1218
import { setPropagationContextOnContext } from '../src/utils/contextData';
@@ -220,15 +226,15 @@ describe('trace', () => {
220226
origin: 'auto.test.origin',
221227
metadata: { requestPath: 'test-path' },
222228
attributes: {
223-
[InternalSentrySemanticAttributes.SOURCE]: 'task',
229+
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'task',
224230
},
225231
},
226232
span => {
227233
expect(span).toBeDefined();
228234
expect(getSpanAttributes(span)).toEqual({
229-
[InternalSentrySemanticAttributes.SOURCE]: 'task',
230-
[InternalSentrySemanticAttributes.ORIGIN]: 'auto.test.origin',
231-
[InternalSentrySemanticAttributes.OP]: 'my-op',
235+
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'task',
236+
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.test.origin',
237+
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'my-op',
232238
[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE]: 1,
233239
});
234240

@@ -376,17 +382,17 @@ describe('trace', () => {
376382
op: 'my-op',
377383
origin: 'auto.test.origin',
378384
attributes: {
379-
[InternalSentrySemanticAttributes.SOURCE]: 'task',
385+
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'task',
380386
},
381387
metadata: { requestPath: 'test-path' },
382388
});
383389

384390
expect(span2).toBeDefined();
385391
expect(getSpanAttributes(span2)).toEqual({
386392
[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE]: 1,
387-
[InternalSentrySemanticAttributes.SOURCE]: 'task',
388-
[InternalSentrySemanticAttributes.ORIGIN]: 'auto.test.origin',
389-
[InternalSentrySemanticAttributes.OP]: 'my-op',
393+
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'task',
394+
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.test.origin',
395+
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'my-op',
390396
});
391397

392398
expect(getSpanMetadata(span2)).toEqual({ requestPath: 'test-path' });

0 commit comments

Comments
 (0)