Skip to content

Commit 9e88097

Browse files
committed
remove trace state handling
1 parent a4c84aa commit 9e88097

File tree

10 files changed

+11
-44
lines changed

10 files changed

+11
-44
lines changed

packages/opentelemetry/src/constants.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ export const SENTRY_TRACE_HEADER = 'sentry-trace';
44
export const SENTRY_BAGGAGE_HEADER = 'baggage';
55

66
export const SENTRY_TRACE_STATE_DSC = 'sentry.dsc';
7-
export const SENTRY_TRACE_STATE_PARENT_SPAN_ID = 'sentry.parent_span_id';
87
export const SENTRY_TRACE_STATE_SAMPLED_NOT_RECORDING = 'sentry.sampled_not_recording';
98
export const SENTRY_TRACE_STATE_URL = 'sentry.url';
109

packages/opentelemetry/src/propagator.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ import {
2525
SENTRY_BAGGAGE_HEADER,
2626
SENTRY_TRACE_HEADER,
2727
SENTRY_TRACE_STATE_DSC,
28-
SENTRY_TRACE_STATE_PARENT_SPAN_ID,
2928
SENTRY_TRACE_STATE_URL,
3029
} from './constants';
3130
import { DEBUG_BUILD } from './debug-build';
3231
import { getScopesFromContext, setScopesOnContext } from './utils/contextData';
3332
import { generateSpanContextForPropagationContext } from './utils/generateSpanContextForPropagationContext';
3433
import { getSamplingDecision } from './utils/getSamplingDecision';
3534
import { setIsSetup } from './utils/setupCheck';
35+
import { spanHasParentId } from './utils/spanTypes';
3636

3737
/** Get the Sentry propagation context from a span context. */
3838
export function getPropagationContextFromSpan(span: Span): PropagationContext {
@@ -44,8 +44,7 @@ export function getPropagationContextFromSpan(span: Span): PropagationContext {
4444
const dscString = traceState ? traceState.get(SENTRY_TRACE_STATE_DSC) : undefined;
4545
const traceStateDsc = dscString ? baggageHeaderToDynamicSamplingContext(dscString) : undefined;
4646

47-
const parentSpanId = traceState ? traceState.get(SENTRY_TRACE_STATE_PARENT_SPAN_ID) || undefined : undefined;
48-
47+
const parentSpanId = spanHasParentId(span) ? span.parentSpanId : undefined;
4948
const sampled = getSamplingDecision(spanContext);
5049

5150
// No trace state? --> Take DSC from root span

packages/opentelemetry/src/setupEventContextTrace.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { getDynamicSamplingContextFromSpan, getRootSpan } from '@sentry/core';
22
import { dropUndefinedKeys } from '@sentry/core';
33
import type { Client } from '@sentry/types';
4-
import { SENTRY_TRACE_STATE_PARENT_SPAN_ID } from './constants';
54
import { getActiveSpan } from './utils/getActiveSpan';
65
import { spanHasParentId } from './utils/spanTypes';
76

@@ -16,16 +15,7 @@ export function setupEventContextTrace(client: Client): void {
1615
}
1716

1817
const spanContext = span.spanContext();
19-
20-
// If we have a parent span id from trace state, use that ('' means no parent should be used)
21-
// Else, pick the one from the span
22-
const parentSpanIdFromTraceState = spanContext.traceState?.get(SENTRY_TRACE_STATE_PARENT_SPAN_ID);
23-
const parent_span_id =
24-
typeof parentSpanIdFromTraceState === 'string'
25-
? parentSpanIdFromTraceState || undefined
26-
: spanHasParentId(span)
27-
? span.parentSpanId
28-
: undefined;
18+
const parent_span_id = spanHasParentId(span) ? span.parentSpanId : undefined;
2919

3020
// If event has already set `trace` context, use that one.
3121
event.contexts = {

packages/opentelemetry/src/spanExporter.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {
1919
} from '@sentry/core';
2020
import { dropUndefinedKeys, logger } from '@sentry/core';
2121
import type { SpanJSON, SpanOrigin, TraceContext, TransactionEvent, TransactionSource } from '@sentry/types';
22-
import { SENTRY_TRACE_STATE_PARENT_SPAN_ID } from './constants';
2322

2423
import { DEBUG_BUILD } from './debug-build';
2524
import { SEMANTIC_ATTRIBUTE_SENTRY_PARENT_IS_REMOTE } from './semanticAttributes';
@@ -207,15 +206,12 @@ function createTransactionForOtelSpan(span: ReadableSpan): TransactionEvent {
207206

208207
const { traceId: trace_id, spanId: span_id } = span.spanContext();
209208

210-
const parentSpanIdFromTraceState = span.spanContext().traceState?.get(SENTRY_TRACE_STATE_PARENT_SPAN_ID);
211-
212209
// If parentSpanIdFromTraceState is defined at all, we want it to take precedence
213210
// In that case, an empty string should be interpreted as "no parent span id",
214211
// even if `span.parentSpanId` is set
215212
// this is the case when we are starting a new trace, where we have a virtual span based on the propagationContext
216213
// We only want to continue the traceId in this case, but ignore the parent span
217-
const parent_span_id =
218-
typeof parentSpanIdFromTraceState === 'string' ? parentSpanIdFromTraceState || undefined : span.parentSpanId;
214+
const parent_span_id = span.parentSpanId;
219215

220216
const status = mapStatus(span);
221217

packages/opentelemetry/src/trace.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Context, Span, SpanContext, SpanOptions, Tracer } from '@opentelemetry/api';
2-
import { INVALID_SPANID, SpanStatusCode, TraceFlags, context, trace } from '@opentelemetry/api';
2+
import { SpanStatusCode, TraceFlags, context, trace } from '@opentelemetry/api';
33
import { suppressTracing } from '@opentelemetry/core';
44
import {
55
SDK_VERSION,
@@ -209,7 +209,6 @@ function getContext(scope: Scope | undefined, forceTransaction: boolean | undefi
209209

210210
const traceState = makeTraceState({
211211
dsc,
212-
parentSpanId: spanId !== INVALID_SPANID ? spanId : undefined,
213212
sampled,
214213
});
215214

packages/opentelemetry/src/utils/generateSpanContextForPropagationContext.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { makeTraceState } from './makeTraceState';
1010
export function generateSpanContextForPropagationContext(propagationContext: PropagationContext): SpanContext {
1111
// We store the DSC as OTEL trace state on the span context
1212
const traceState = makeTraceState({
13-
parentSpanId: propagationContext.parentSpanId,
1413
dsc: propagationContext.dsc,
1514
sampled: propagationContext.sampled,
1615
});

packages/opentelemetry/src/utils/makeTraceState.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,24 @@
11
import { TraceState } from '@opentelemetry/core';
22
import { dynamicSamplingContextToSentryBaggageHeader } from '@sentry/core';
33
import type { DynamicSamplingContext } from '@sentry/types';
4-
import {
5-
SENTRY_TRACE_STATE_DSC,
6-
SENTRY_TRACE_STATE_PARENT_SPAN_ID,
7-
SENTRY_TRACE_STATE_SAMPLED_NOT_RECORDING,
8-
} from '../constants';
4+
import { SENTRY_TRACE_STATE_DSC, SENTRY_TRACE_STATE_SAMPLED_NOT_RECORDING } from '../constants';
95

106
/**
117
* Generate a TraceState for the given data.
128
*/
139
export function makeTraceState({
14-
parentSpanId,
1510
dsc,
1611
sampled,
1712
}: {
13+
/** @deprecated parentSpanId does not do anything anymore and will be removed in v9. */
1814
parentSpanId?: string;
1915
dsc?: Partial<DynamicSamplingContext>;
2016
sampled?: boolean;
2117
}): TraceState {
2218
// We store the DSC as OTEL trace state on the span context
2319
const dscString = dsc ? dynamicSamplingContextToSentryBaggageHeader(dsc) : undefined;
2420

25-
// We _always_ set the parent span ID, even if it is empty
26-
// If we'd set this to 'undefined' we could not know if the trace state was set, but there was no parentSpanId,
27-
// vs the trace state was not set at all (in which case we want to do fallback handling)
28-
// If `''`, it should be considered "no parent"
29-
const traceStateBase = new TraceState().set(SENTRY_TRACE_STATE_PARENT_SPAN_ID, parentSpanId || '');
21+
const traceStateBase = new TraceState();
3022

3123
const traceStateWithDsc = dscString ? traceStateBase.set(SENTRY_TRACE_STATE_DSC, dscString) : traceStateBase;
3224

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,6 @@ describe('Integration | Transactions', () => {
327327
const parentSpanId = '6e0c63257de34c92';
328328

329329
const traceState = makeTraceState({
330-
parentSpanId,
331330
dsc: undefined,
332331
sampled: true,
333332
});

packages/opentelemetry/test/propagator.test.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@ describe('SentryPropagator', () => {
181181
traceFlags: TraceFlags.SAMPLED,
182182
isRemote: true,
183183
traceState: makeTraceState({
184-
parentSpanId: '6e0c63257de34c92',
185184
dsc: {
186185
transaction: 'sampled-transaction',
187186
sampled: 'true',
@@ -256,7 +255,6 @@ describe('SentryPropagator', () => {
256255
traceFlags: TraceFlags.NONE,
257256
isRemote: true,
258257
traceState: makeTraceState({
259-
parentSpanId: '6e0c63257de34c92',
260258
dsc: {
261259
transaction: 'sampled-transaction',
262260
sampled: 'false',
@@ -291,7 +289,6 @@ describe('SentryPropagator', () => {
291289
isRemote: true,
292290
traceState: makeTraceState({
293291
sampled: false,
294-
parentSpanId: '6e0c63257de34c92',
295292
dsc: {
296293
transaction: 'sampled-transaction',
297294
trace_id: 'dsc_trace_id',
@@ -557,7 +554,7 @@ describe('SentryPropagator', () => {
557554
spanId: '6e0c63257de34c92',
558555
traceFlags: TraceFlags.SAMPLED,
559556
traceId: 'd4cda95b652f4a1592b449d5929fda1b',
560-
traceState: makeTraceState({ parentSpanId: '6e0c63257de34c92' }),
557+
traceState: makeTraceState({}),
561558
});
562559
expect(getSamplingDecision(trace.getSpanContext(context)!)).toBe(true);
563560
});
@@ -571,7 +568,7 @@ describe('SentryPropagator', () => {
571568
spanId: '6e0c63257de34c92',
572569
traceFlags: TraceFlags.NONE,
573570
traceId: 'd4cda95b652f4a1592b449d5929fda1b',
574-
traceState: makeTraceState({ parentSpanId: '6e0c63257de34c92', sampled: false }),
571+
traceState: makeTraceState({ sampled: false }),
575572
});
576573
expect(getSamplingDecision(trace.getSpanContext(context)!)).toBe(false);
577574
});
@@ -585,7 +582,7 @@ describe('SentryPropagator', () => {
585582
spanId: '6e0c63257de34c92',
586583
traceFlags: TraceFlags.NONE,
587584
traceId: 'd4cda95b652f4a1592b449d5929fda1b',
588-
traceState: makeTraceState({ parentSpanId: '6e0c63257de34c92' }),
585+
traceState: makeTraceState({}),
589586
});
590587
expect(getSamplingDecision(trace.getSpanContext(context)!)).toBe(undefined);
591588
});
@@ -635,7 +632,6 @@ describe('SentryPropagator', () => {
635632
traceFlags: TraceFlags.SAMPLED,
636633
traceId: 'd4cda95b652f4a1592b449d5929fda1b',
637634
traceState: makeTraceState({
638-
parentSpanId: '6e0c63257de34c92',
639635
dsc: {
640636
environment: 'production',
641637
release: '1.0.0',

packages/opentelemetry/test/trace.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,6 @@ describe('trace', () => {
10841084
isRemote: false,
10851085
traceFlags: TraceFlags.SAMPLED,
10861086
traceState: makeTraceState({
1087-
parentSpanId: '1121201211212011',
10881087
dsc: {
10891088
release: '1.0',
10901089
environment: 'production',
@@ -1114,7 +1113,6 @@ describe('trace', () => {
11141113
isRemote: true,
11151114
traceFlags: TraceFlags.SAMPLED,
11161115
traceState: makeTraceState({
1117-
parentSpanId: '1121201211212011',
11181116
dsc: {
11191117
release: '1.0',
11201118
environment: 'production',

0 commit comments

Comments
 (0)