Skip to content

Commit 05ca00e

Browse files
committed
feat!: Remove spanId from propagation context
Closes #12385 This also deprecates `getPropagationContextFromSpan` as it is no longer used/needed. We may think about removing this in v9, but IMHO we can also just leave this for v9, it does not hurt too much to have it in there...
1 parent 031ef3a commit 05ca00e

File tree

12 files changed

+21
-56
lines changed

12 files changed

+21
-56
lines changed

packages/core/src/currentScopes.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { getAsyncContextStrategy } from './asyncContext';
22
import { getGlobalSingleton, getMainCarrier } from './carrier';
33
import { Scope } from './scope';
44
import type { Client, TraceContext } from './types-hoist';
5+
import { generateSpanId } from './utils-hoist';
56
import { dropUndefinedKeys } from './utils-hoist/object';
67

78
/**
@@ -126,13 +127,11 @@ export function getClient<C extends Client>(): C | undefined {
126127
export function getTraceContextFromScope(scope: Scope): TraceContext {
127128
const propagationContext = scope.getPropagationContext();
128129

129-
// TODO(v9): Use generateSpanId() instead of spanId
130-
// eslint-disable-next-line deprecation/deprecation
131-
const { traceId, spanId, parentSpanId } = propagationContext;
130+
const { traceId, parentSpanId } = propagationContext;
132131

133132
const traceContext: TraceContext = dropUndefinedKeys({
134133
trace_id: traceId,
135-
span_id: spanId,
134+
span_id: generateSpanId(),
136135
parent_span_id: parentSpanId,
137136
});
138137

packages/core/src/scope.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { updateSession } from './session';
2323
import { isPlainObject } from './utils-hoist/is';
2424
import { logger } from './utils-hoist/logger';
2525
import { uuid4 } from './utils-hoist/misc';
26-
import { generateSpanId, generateTraceId } from './utils-hoist/propagationContext';
26+
import { generateTraceId } from './utils-hoist/propagationContext';
2727
import { dateTimestampInSeconds } from './utils-hoist/time';
2828
import { merge } from './utils/merge';
2929
import { _getSpanForScope, _setSpanForScope } from './utils/spanOnScope';
@@ -156,7 +156,6 @@ export class Scope {
156156
this._sdkProcessingMetadata = {};
157157
this._propagationContext = {
158158
traceId: generateTraceId(),
159-
spanId: generateSpanId(),
160159
};
161160
}
162161

@@ -575,14 +574,8 @@ export class Scope {
575574
/**
576575
* Add propagation context to the scope, used for distributed tracing
577576
*/
578-
public setPropagationContext(
579-
context: Omit<PropagationContext, 'spanId'> & Partial<Pick<PropagationContext, 'spanId'>>,
580-
): this {
581-
this._propagationContext = {
582-
// eslint-disable-next-line deprecation/deprecation
583-
spanId: generateSpanId(),
584-
...context,
585-
};
577+
public setPropagationContext(context: PropagationContext): this {
578+
this._propagationContext = context;
586579
return this;
587580
}
588581

packages/core/src/types-hoist/tracing.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,6 @@ export interface PropagationContext {
1515
* Either represents the incoming `traceId` or the `traceId` generated by the current SDK, if there was no incoming trace.
1616
*/
1717
traceId: string;
18-
/**
19-
* Represents the execution context of the current SDK. This acts as a fallback value to associate events with a
20-
* particular execution context when performance monitoring is disabled.
21-
*
22-
* The ID of a current span (if one exists) should have precedence over this value when propagating trace data.
23-
*
24-
* @deprecated This value will not be used anymore in the future, and should not be set or read anymore.
25-
*/
26-
spanId: string;
2718
/**
2819
* Represents the sampling decision of the incoming trace.
2920
*

packages/core/src/utils-hoist/propagationContext.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { uuid4 } from './misc';
99
export function generatePropagationContext(): PropagationContext {
1010
return {
1111
traceId: generateTraceId(),
12-
spanId: generateSpanId(),
1312
};
1413
}
1514

packages/core/src/utils-hoist/tracing.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,14 @@ export function propagationContextFromHeaders(
5555
const dynamicSamplingContext = baggageHeaderToDynamicSamplingContext(baggage);
5656

5757
if (!traceparentData || !traceparentData.traceId) {
58-
return { traceId: generateTraceId(), spanId: generateSpanId() };
58+
return { traceId: generateTraceId() };
5959
}
6060

6161
const { traceId, parentSpanId, parentSampled } = traceparentData;
6262

63-
const virtualSpanId = generateSpanId();
64-
6563
return {
6664
traceId,
6765
parentSpanId,
68-
spanId: virtualSpanId,
6966
sampled: parentSampled,
7067
dsc: dynamicSamplingContext || {}, // If we have traceparent data but no DSC it means we are not head of trace and we must freeze it
7168
};

packages/core/src/utils/traceData.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { isEnabled } from '../exports';
55
import type { Scope } from '../scope';
66
import { getDynamicSamplingContextFromScope, getDynamicSamplingContextFromSpan } from '../tracing';
77
import type { SerializedTraceData, Span } from '../types-hoist';
8+
import { generateSpanId } from '../utils-hoist';
89
import { dynamicSamplingContextToSentryBaggageHeader } from '../utils-hoist/baggage';
910
import { logger } from '../utils-hoist/logger';
1011
import { TRACEPARENT_REGEXP, generateSentryTraceHeader } from '../utils-hoist/tracing';
@@ -55,8 +56,6 @@ export function getTraceData(options: { span?: Span } = {}): SerializedTraceData
5556
* Get a sentry-trace header value for the given scope.
5657
*/
5758
function scopeToTraceHeader(scope: Scope): string {
58-
// TODO(v9): Use generateSpanId() instead of spanId
59-
// eslint-disable-next-line deprecation/deprecation
60-
const { traceId, sampled, spanId } = scope.getPropagationContext();
61-
return generateSentryTraceHeader(traceId, spanId, sampled);
59+
const { traceId, sampled } = scope.getPropagationContext();
60+
return generateSentryTraceHeader(traceId, generateSpanId(), sampled);
6261
}

packages/nextjs/src/common/wrapGenerationFunctionWithSentry.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
SPAN_STATUS_OK,
77
Scope,
88
captureException,
9-
generateSpanId,
109
generateTraceId,
1110
getActiveSpan,
1211
getCapturedScopesOnSpan,
@@ -90,7 +89,6 @@ export function wrapGenerationFunctionWithSentry<F extends (...args: any[]) => a
9089
? propagationContextFromHeaders(headersDict['sentry-trace'], headersDict['baggage'])
9190
: {
9291
traceId: requestTraceId || generateTraceId(),
93-
spanId: generateSpanId(),
9492
},
9593
);
9694
scope.setPropagationContext(propagationContext);

packages/nextjs/src/common/wrapServerComponentWithSentry.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
SPAN_STATUS_OK,
77
Scope,
88
captureException,
9-
generateSpanId,
109
generateTraceId,
1110
getActiveSpan,
1211
getCapturedScopesOnSpan,
@@ -69,7 +68,6 @@ export function wrapServerComponentWithSentry<F extends (...args: any[]) => any>
6968
? propagationContextFromHeaders(headersDict['sentry-trace'], headersDict['baggage'])
7069
: {
7170
traceId: requestTraceId || generateTraceId(),
72-
spanId: generateSpanId(),
7371
},
7472
);
7573

packages/node/src/integrations/anr/worker.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Session as InspectorSession } from 'node:inspector';
22
import { parentPort, workerData } from 'node:worker_threads';
33
import type { DebugImage, Event, ScopeData, Session, StackFrame } from '@sentry/core';
4+
import { generateSpanId } from '@sentry/core';
45
import {
56
applyScopeDataToEvent,
67
callFrameToStackFrame,
@@ -121,13 +122,11 @@ function applyScopeToEvent(event: Event, scope: ScopeData): void {
121122
applyScopeDataToEvent(event, scope);
122123

123124
if (!event.contexts?.trace) {
124-
// TODO(v9): Use generateSpanId() instead of spanId
125-
// eslint-disable-next-line deprecation/deprecation
126-
const { traceId, spanId, parentSpanId } = scope.propagationContext;
125+
const { traceId, parentSpanId } = scope.propagationContext;
127126
event.contexts = {
128127
trace: {
129128
trace_id: traceId,
130-
span_id: spanId,
129+
span_id: generateSpanId(),
131130
parent_span_id: parentSpanId,
132131
},
133132
...event.contexts,

packages/opentelemetry/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export { setOpenTelemetryContextAsyncContextStrategy } from './asyncContextStrat
4747
export { wrapContextManagerClass } from './contextManager';
4848
export {
4949
SentryPropagator,
50+
// eslint-disable-next-line deprecation/deprecation
5051
getPropagationContextFromSpan,
5152
shouldPropagateTraceForUrl,
5253
} from './propagator';

packages/opentelemetry/src/propagator.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,13 @@ import { makeTraceState } from './utils/makeTraceState';
3434
import { setIsSetup } from './utils/setupCheck';
3535
import { spanHasParentId } from './utils/spanTypes';
3636

37-
/** Get the Sentry propagation context from a span context. */
37+
/**
38+
* Get the Sentry propagation context from a span context.
39+
* @deprecated This method is not used anymore and may be removed in a future major.
40+
*/
3841
export function getPropagationContextFromSpan(span: Span): PropagationContext {
3942
const spanContext = span.spanContext();
40-
const { traceId, spanId, traceState } = spanContext;
43+
const { traceId, traceState } = spanContext;
4144

4245
// When we have a dsc trace state, it means this came from the incoming trace
4346
// Then this takes presedence over the root span
@@ -52,7 +55,6 @@ export function getPropagationContextFromSpan(span: Span): PropagationContext {
5255

5356
return {
5457
traceId,
55-
spanId,
5658
sampled,
5759
parentSpanId,
5860
dsc,
@@ -234,9 +236,7 @@ export function getInjectionData(context: Context): {
234236
return {
235237
dynamicSamplingContext,
236238
traceId: propagationContext.traceId,
237-
// TODO(v9): Use generateSpanId() instead
238-
// eslint-disable-next-line deprecation/deprecation
239-
spanId: propagationContext.spanId,
239+
spanId: generateSpanId(),
240240
sampled: propagationContext.sampled,
241241
};
242242
}

packages/opentelemetry/src/sampler.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {
1919
} from '@sentry/core';
2020
import { SENTRY_TRACE_STATE_SAMPLED_NOT_RECORDING, SENTRY_TRACE_STATE_URL } from './constants';
2121
import { DEBUG_BUILD } from './debug-build';
22-
import { getPropagationContextFromSpan } from './propagator';
2322
import { getSamplingDecision } from './utils/getSamplingDecision';
2423
import { inferSpanData } from './utils/parseSpanDescription';
2524
import { setIsSetup } from './utils/setupCheck';
@@ -138,22 +137,14 @@ export class SentrySampler implements Sampler {
138137
}
139138
}
140139

141-
function getParentRemoteSampled(parentSpan: Span): boolean | undefined {
142-
const traceId = parentSpan.spanContext().traceId;
143-
const traceparentData = getPropagationContextFromSpan(parentSpan);
144-
145-
// Only inherit sampled if `traceId` is the same
146-
return traceparentData && traceId === traceparentData.traceId ? traceparentData.sampled : undefined;
147-
}
148-
149140
function getParentSampled(parentSpan: Span, traceId: string, spanName: string): boolean | undefined {
150141
const parentContext = parentSpan.spanContext();
151142

152143
// Only inherit sample rate if `traceId` is the same
153144
// Note for testing: `isSpanContextValid()` checks the format of the traceId/spanId, so we need to pass valid ones
154145
if (isSpanContextValid(parentContext) && parentContext.traceId === traceId) {
155146
if (parentContext.isRemote) {
156-
const parentSampled = getParentRemoteSampled(parentSpan);
147+
const parentSampled = getSamplingDecision(parentSpan.spanContext());
157148
DEBUG_BUILD &&
158149
logger.log(`[Tracing] Inheriting remote parent's sampled decision for ${spanName}: ${parentSampled}`);
159150
return parentSampled;

0 commit comments

Comments
 (0)