From 1421400286fbe0e3fbcdfdb7e88e17c81d160e91 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Tue, 27 Feb 2024 16:15:25 +0000 Subject: [PATCH 1/2] 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). --- .../test/integration/transactions.test.ts | 13 +++++++++- .../opentelemetry/src/semanticAttributes.ts | 8 ------ packages/opentelemetry/src/spanExporter.ts | 20 +++++++------- packages/opentelemetry/src/trace.ts | 17 ++++++++---- .../src/utils/addOriginToSpan.ts | 5 ++-- .../test/integration/transactions.test.ts | 13 +++++++++- packages/opentelemetry/test/trace.test.ts | 26 ++++++++++++------- 7 files changed, 64 insertions(+), 38 deletions(-) diff --git a/packages/node-experimental/test/integration/transactions.test.ts b/packages/node-experimental/test/integration/transactions.test.ts index b1fbc25cdceb..05a7f1840ec1 100644 --- a/packages/node-experimental/test/integration/transactions.test.ts +++ b/packages/node-experimental/test/integration/transactions.test.ts @@ -70,6 +70,9 @@ describe('Integration | Transactions', () => { otel: { attributes: { 'test.outer': 'test value', + 'sentry.op': 'test op', + 'sentry.origin': 'auto.test', + 'sentry.source': 'task', }, resource: { 'service.name': 'node-experimental', @@ -241,6 +244,9 @@ describe('Integration | Transactions', () => { otel: expect.objectContaining({ attributes: { 'test.outer': 'test value', + 'sentry.op': 'test op', + 'sentry.origin': 'auto.test', + 'sentry.source': 'task', }, }), trace: { @@ -283,6 +289,7 @@ describe('Integration | Transactions', () => { otel: expect.objectContaining({ attributes: { 'test.outer': 'test value b', + 'sentry.op': 'test op b', }, }), trace: { @@ -513,7 +520,11 @@ describe('Integration | Transactions', () => { expect.objectContaining({ contexts: expect.objectContaining({ otel: expect.objectContaining({ - attributes: {}, + attributes: { + 'sentry.op': 'test op', + 'sentry.origin': 'auto.test', + 'sentry.source': 'task', + }, }), trace: { data: { diff --git a/packages/opentelemetry/src/semanticAttributes.ts b/packages/opentelemetry/src/semanticAttributes.ts index 49983f14dcd2..8f61318a3ecc 100644 --- a/packages/opentelemetry/src/semanticAttributes.ts +++ b/packages/opentelemetry/src/semanticAttributes.ts @@ -3,13 +3,5 @@ * No guarantees apply to these attributes, and the may change/disappear at any time. */ export const InternalSentrySemanticAttributes = { - ORIGIN: 'sentry.origin', - OP: 'sentry.op', - SOURCE: 'sentry.source', PARENT_SAMPLED: 'sentry.parentSampled', - BREADCRUMB_TYPE: 'sentry.breadcrumb.type', - BREADCRUMB_LEVEL: 'sentry.breadcrumb.level', - BREADCRUMB_EVENT_ID: 'sentry.breadcrumb.event_id', - BREADCRUMB_CATEGORY: 'sentry.breadcrumb.category', - BREADCRUMB_DATA: 'sentry.breadcrumb.data', } as const; diff --git a/packages/opentelemetry/src/spanExporter.ts b/packages/opentelemetry/src/spanExporter.ts index 3a0612e41365..2d58f9ffef2e 100644 --- a/packages/opentelemetry/src/spanExporter.ts +++ b/packages/opentelemetry/src/spanExporter.ts @@ -4,8 +4,13 @@ import { ExportResultCode } from '@opentelemetry/core'; import type { ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-base'; import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; import type { Transaction } from '@sentry/core'; -import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core'; -import { SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, getCurrentHub } from '@sentry/core'; +import { + SEMANTIC_ATTRIBUTE_SENTRY_OP, + SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, + SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, + SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, + getCurrentHub, +} from '@sentry/core'; import type { Scope, Span as SentrySpan, SpanOrigin, TransactionSource } from '@sentry/types'; import { addNonEnumerableProperty, dropUndefinedKeys, logger } from '@sentry/utils'; import { startTransaction } from './custom/transaction'; @@ -132,9 +137,9 @@ function shouldCleanupSpan(span: ReadableSpan, maxStartTimeOffsetSeconds: number function parseSpan(span: ReadableSpan): { op?: string; origin?: SpanOrigin; source?: TransactionSource } { const attributes = span.attributes; - const origin = attributes[InternalSentrySemanticAttributes.ORIGIN] as SpanOrigin | undefined; - const op = attributes[InternalSentrySemanticAttributes.OP] as string | undefined; - const source = attributes[InternalSentrySemanticAttributes.SOURCE] as TransactionSource | undefined; + const origin = attributes[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN] as SpanOrigin | undefined; + const op = attributes[SEMANTIC_ATTRIBUTE_SENTRY_OP] as string | undefined; + const source = attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE] as TransactionSource | undefined; return { origin, op, source }; } @@ -278,11 +283,6 @@ function removeSentryAttributes(data: Record): Record { otel: { attributes: { 'test.outer': 'test value', + 'sentry.op': 'test op', + 'sentry.origin': 'auto.test', + 'sentry.source': 'task', }, resource: { 'service.name': 'opentelemetry-test', @@ -245,6 +248,9 @@ describe('Integration | Transactions', () => { otel: expect.objectContaining({ attributes: { 'test.outer': 'test value', + 'sentry.op': 'test op', + 'sentry.origin': 'auto.test', + 'sentry.source': 'task', }, }), trace: { @@ -287,6 +293,7 @@ describe('Integration | Transactions', () => { otel: expect.objectContaining({ attributes: { 'test.outer': 'test value b', + 'sentry.op': 'test op b', }, }), trace: { @@ -364,7 +371,11 @@ describe('Integration | Transactions', () => { expect.objectContaining({ contexts: expect.objectContaining({ otel: expect.objectContaining({ - attributes: {}, + attributes: { + 'sentry.op': 'test op', + 'sentry.origin': 'auto.test', + 'sentry.source': 'task', + }, }), trace: { data: { diff --git a/packages/opentelemetry/test/trace.test.ts b/packages/opentelemetry/test/trace.test.ts index 7cc845232ec8..da1e7c7ff963 100644 --- a/packages/opentelemetry/test/trace.test.ts +++ b/packages/opentelemetry/test/trace.test.ts @@ -3,10 +3,16 @@ import { SpanKind } from '@opentelemetry/api'; import { TraceFlags, context, trace } from '@opentelemetry/api'; import type { ReadableSpan } from '@opentelemetry/sdk-trace-base'; import { Span as SpanClass } from '@opentelemetry/sdk-trace-base'; -import { SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, getClient, getCurrentScope, spanToJSON } from '@sentry/core'; +import { + SEMANTIC_ATTRIBUTE_SENTRY_OP, + SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, + SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, + SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, + getClient, + getCurrentScope, +} from '@sentry/core'; import type { Event, PropagationContext, Scope } from '@sentry/types'; -import { InternalSentrySemanticAttributes } from '../src/semanticAttributes'; import { startInactiveSpan, startSpan, startSpanManual } from '../src/trace'; import type { AbstractSpan } from '../src/types'; import { setPropagationContextOnContext } from '../src/utils/contextData'; @@ -220,15 +226,15 @@ describe('trace', () => { origin: 'auto.test.origin', metadata: { requestPath: 'test-path' }, attributes: { - [InternalSentrySemanticAttributes.SOURCE]: 'task', + [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'task', }, }, span => { expect(span).toBeDefined(); expect(getSpanAttributes(span)).toEqual({ - [InternalSentrySemanticAttributes.SOURCE]: 'task', - [InternalSentrySemanticAttributes.ORIGIN]: 'auto.test.origin', - [InternalSentrySemanticAttributes.OP]: 'my-op', + [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'task', + [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.test.origin', + [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'my-op', [SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE]: 1, }); @@ -481,7 +487,7 @@ describe('trace', () => { op: 'my-op', origin: 'auto.test.origin', attributes: { - [InternalSentrySemanticAttributes.SOURCE]: 'task', + [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'task', }, metadata: { requestPath: 'test-path' }, }); @@ -489,9 +495,9 @@ describe('trace', () => { expect(span2).toBeDefined(); expect(getSpanAttributes(span2)).toEqual({ [SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE]: 1, - [InternalSentrySemanticAttributes.SOURCE]: 'task', - [InternalSentrySemanticAttributes.ORIGIN]: 'auto.test.origin', - [InternalSentrySemanticAttributes.OP]: 'my-op', + [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'task', + [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.test.origin', + [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'my-op', }); expect(getSpanMetadata(span2)).toEqual({ requestPath: 'test-path' }); From 79dc36c19b90de5abd792e21aff647b1fcc70b9b Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Wed, 28 Feb 2024 10:44:08 +0000 Subject: [PATCH 2/2] fix test --- packages/opentelemetry/test/trace.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/opentelemetry/test/trace.test.ts b/packages/opentelemetry/test/trace.test.ts index da1e7c7ff963..126586d29538 100644 --- a/packages/opentelemetry/test/trace.test.ts +++ b/packages/opentelemetry/test/trace.test.ts @@ -10,6 +10,7 @@ import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, getClient, getCurrentScope, + spanToJSON, } from '@sentry/core'; import type { Event, PropagationContext, Scope } from '@sentry/types';