From 378cf539a07cb38f5eb9fca31d04181b83b495e2 Mon Sep 17 00:00:00 2001 From: Martin Sonnberger Date: Fri, 9 Oct 2026 10:08:07 +0200 Subject: [PATCH 1/2] fix(core): strip internal custom span name from streamed spans Co-Authored-By: OpenAI ChatGPT --- .../pageload-updateSpanName/test.ts | 2 +- packages/core/src/utils/spanUtils.ts | 6 +++++- packages/core/test/lib/utils/spanUtils.test.ts | 2 ++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/pageload-updateSpanName/test.ts b/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/pageload-updateSpanName/test.ts index 0ee7a634717f..b62585b2f881 100644 --- a/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/pageload-updateSpanName/test.ts +++ b/dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/pageload-updateSpanName/test.ts @@ -34,7 +34,7 @@ sentryTest( [SENTRY_OP]: { type: 'string', value: 'pageload' }, }); - expect(attributes[SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME]).toEqual({ type: 'string', value: 'new name' }); + expect(attributes[SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME]).toBeUndefined(); expect(pageloadSpan.name).toBe('new name'); diff --git a/packages/core/src/utils/spanUtils.ts b/packages/core/src/utils/spanUtils.ts index e1615b9bf5c4..7357c32a24f1 100644 --- a/packages/core/src/utils/spanUtils.ts +++ b/packages/core/src/utils/spanUtils.ts @@ -270,12 +270,16 @@ function getOtelParentSpanId(span: OpenTelemetrySdkTraceBaseSpan): string | unde * The returned serilaized spans must not be consumed by users or SDK integrations. */ export function streamedSpanJsonToSerializedSpan(spanJson: StreamedSpanJSON): SerializedStreamedSpan { + const attributes = serializeAttributes(spanJson.attributes); + // oxlint-disable-next-line typescript/no-dynamic-delete + delete attributes[SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME]; + return { ...spanJson, // We only ever send ended spans, but fall back to the start time (i.e. duration 0) so that // sent spans always carry an end timestamp. end_timestamp: spanJson.end_timestamp ?? spanJson.start_timestamp, - attributes: serializeAttributes(spanJson.attributes), + attributes, links: spanJson.links?.map(link => ({ ...link, attributes: serializeAttributes(link.attributes), diff --git a/packages/core/test/lib/utils/spanUtils.test.ts b/packages/core/test/lib/utils/spanUtils.test.ts index 032a09ce1667..42895947d1ff 100644 --- a/packages/core/test/lib/utils/spanUtils.test.ts +++ b/packages/core/test/lib/utils/spanUtils.test.ts @@ -6,6 +6,7 @@ import { Scope, SentryNonRecordingSpan, SentrySpan, + SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME, setCurrentClient, SPAN_STATUS_ERROR, SPAN_STATUS_OK, @@ -681,6 +682,7 @@ describe('spanToStaticSpanJSON', () => { attr2: 2, attr3: true, attr4: [1, 2, 3], + [SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME]: 'test name', [SENTRY_OP]: 'test op', [SENTRY_ORIGIN]: 'auto', }, From 9f984f725e422ffd1cc4cd4b2f2affa968d3ddd6 Mon Sep 17 00:00:00 2001 From: Martin Sonnberger Date: Fri, 9 Oct 2026 11:55:32 +0200 Subject: [PATCH 2/2] move to captureSpan --- packages/core/src/tracing/spans/captureSpan.ts | 5 +++++ packages/core/src/utils/spanUtils.ts | 6 +----- packages/core/test/lib/utils/spanUtils.test.ts | 2 -- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/core/src/tracing/spans/captureSpan.ts b/packages/core/src/tracing/spans/captureSpan.ts index 60a68697ae58..886f0d95cc0e 100644 --- a/packages/core/src/tracing/spans/captureSpan.ts +++ b/packages/core/src/tracing/spans/captureSpan.ts @@ -1,6 +1,7 @@ import type { RawAttributes } from '../../attributes'; import type { Client } from '../../client'; import type { ScopeData } from '../../scope'; +import { SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME } from '../../semanticAttributes'; import type { SerializedStreamedSpan, Span, SpanAttributeValue, SpanJSON, StreamedSpanJSON } from '../../types/span'; import { getCombinedScopeData } from '../../utils/scopeData'; import { @@ -45,6 +46,10 @@ export type SerializedStreamedSpanWithSegmentSpan = SerializedStreamedSpan & { export function captureSpan(span: Span, client: Client): SerializedStreamedSpanWithSegmentSpan { // Convert to JSON FIRST - we cannot write to an already-ended span const spanJSON = spanToJSON(span); + if (spanJSON.attributes) { + // oxlint-disable-next-line typescript/no-dynamic-delete + delete spanJSON.attributes[SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME]; + } const segmentSpan = INTERNAL_getSegmentSpan(span); const serializedSegmentSpan = spanToJSON(segmentSpan); diff --git a/packages/core/src/utils/spanUtils.ts b/packages/core/src/utils/spanUtils.ts index 7357c32a24f1..e1615b9bf5c4 100644 --- a/packages/core/src/utils/spanUtils.ts +++ b/packages/core/src/utils/spanUtils.ts @@ -270,16 +270,12 @@ function getOtelParentSpanId(span: OpenTelemetrySdkTraceBaseSpan): string | unde * The returned serilaized spans must not be consumed by users or SDK integrations. */ export function streamedSpanJsonToSerializedSpan(spanJson: StreamedSpanJSON): SerializedStreamedSpan { - const attributes = serializeAttributes(spanJson.attributes); - // oxlint-disable-next-line typescript/no-dynamic-delete - delete attributes[SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME]; - return { ...spanJson, // We only ever send ended spans, but fall back to the start time (i.e. duration 0) so that // sent spans always carry an end timestamp. end_timestamp: spanJson.end_timestamp ?? spanJson.start_timestamp, - attributes, + attributes: serializeAttributes(spanJson.attributes), links: spanJson.links?.map(link => ({ ...link, attributes: serializeAttributes(link.attributes), diff --git a/packages/core/test/lib/utils/spanUtils.test.ts b/packages/core/test/lib/utils/spanUtils.test.ts index 42895947d1ff..032a09ce1667 100644 --- a/packages/core/test/lib/utils/spanUtils.test.ts +++ b/packages/core/test/lib/utils/spanUtils.test.ts @@ -6,7 +6,6 @@ import { Scope, SentryNonRecordingSpan, SentrySpan, - SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME, setCurrentClient, SPAN_STATUS_ERROR, SPAN_STATUS_OK, @@ -682,7 +681,6 @@ describe('spanToStaticSpanJSON', () => { attr2: 2, attr3: true, attr4: [1, 2, 3], - [SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME]: 'test name', [SENTRY_OP]: 'test op', [SENTRY_ORIGIN]: 'auto', },