Skip to content

Commit a7fc486

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... fix tests remove unneeded test fix stuff fix tests better test fix test
1 parent e48ffef commit a7fc486

File tree

29 files changed

+62
-397
lines changed

29 files changed

+62
-397
lines changed

dev-packages/browser-integration-tests/suites/public-api/startSpan/parallel-root-spans-with-parentSpanId/subject.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
Sentry.getCurrentScope().setPropagationContext({
22
parentSpanId: '1234567890123456',
3-
spanId: '123456789012345x',
43
traceId: '12345678901234567890123456789012',
54
});
65

dev-packages/node-integration-tests/suites/public-api/startSpan/parallel-root-spans/scenario.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ Sentry.init({
1010

1111
Sentry.getCurrentScope().setPropagationContext({
1212
parentSpanId: '1234567890123456',
13-
spanId: '123456789012345x',
1413
traceId: '12345678901234567890123456789012',
1514
});
1615

dev-packages/node-integration-tests/suites/public-api/startSpan/parallel-spans-in-scope-with-parentSpanId/scenario.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ Sentry.init({
1111
Sentry.withScope(scope => {
1212
scope.setPropagationContext({
1313
parentSpanId: '1234567890123456',
14-
spanId: '123456789012345x',
1514
traceId: '12345678901234567890123456789012',
1615
});
1716

dev-packages/node-integration-tests/suites/tracing/meta-tags-twp-errors/test.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,18 @@ describe('errors in TwP mode have same trace in trace context and getTraceData()
4141

4242
const traceData = contexts?.traceData || {};
4343

44-
expect(traceData['sentry-trace']).toEqual(`${trace_id}-${span_id}`);
44+
expect(traceData['sentry-trace']).toMatch(/^[a-f0-9]{32}-[a-f0-9]{16}$/);
45+
expect(traceData['sentry-trace']).toContain(`${trace_id}-`);
46+
// span_id is a random span ID
47+
expect(traceData['sentry-trace']).not.toContain(span_id);
48+
4549
expect(traceData.baggage).toContain(`sentry-trace_id=${trace_id}`);
4650
expect(traceData.baggage).not.toContain('sentry-sampled=');
4751

48-
expect(traceData.metaTags).toContain(`<meta name="sentry-trace" content="${trace_id}-${span_id}"/>`);
52+
expect(traceData.metaTags).toMatch(/<meta name="sentry-trace" content="[a-f0-9]{32}-[a-f0-9]{16}"\/>/);
53+
expect(traceData.metaTags).toContain(`<meta name="sentry-trace" content="${trace_id}-`);
54+
// span_id is a random span ID
55+
expect(traceData.metaTags).not.toContain(span_id);
4956
expect(traceData.metaTags).toContain(`sentry-trace_id=${trace_id}`);
5057
expect(traceData.metaTags).not.toContain('sentry-sampled=');
5158
},

packages/browser/test/tracing/browserTracingIntegration.test.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -643,19 +643,15 @@ describe('browserTracingIntegration', () => {
643643
const newCurrentScopePropCtx = getCurrentScope().getPropagationContext();
644644

645645
expect(oldCurrentScopePropCtx).toEqual({
646-
spanId: expect.stringMatching(/[a-f0-9]{16}/),
647646
traceId: expect.stringMatching(/[a-f0-9]{32}/),
648647
});
649648
expect(oldIsolationScopePropCtx).toEqual({
650-
spanId: expect.stringMatching(/[a-f0-9]{16}/),
651649
traceId: expect.stringMatching(/[a-f0-9]{32}/),
652650
});
653651
expect(newCurrentScopePropCtx).toEqual({
654-
spanId: expect.stringMatching(/[a-f0-9]{16}/),
655652
traceId: expect.stringMatching(/[a-f0-9]{32}/),
656653
});
657654
expect(newIsolationScopePropCtx).toEqual({
658-
spanId: expect.stringMatching(/[a-f0-9]{16}/),
659655
traceId: expect.stringMatching(/[a-f0-9]{32}/),
660656
});
661657

@@ -680,16 +676,13 @@ describe('browserTracingIntegration', () => {
680676

681677
const propCtxBeforeEnd = getCurrentScope().getPropagationContext();
682678
expect(propCtxBeforeEnd).toStrictEqual({
683-
spanId: expect.stringMatching(/[a-f0-9]{16}/),
684679
traceId: expect.stringMatching(/[a-f0-9]{32}/),
685680
});
686681

687682
navigationSpan!.end();
688683

689684
const propCtxAfterEnd = getCurrentScope().getPropagationContext();
690685
expect(propCtxAfterEnd).toStrictEqual({
691-
// eslint-disable-next-line deprecation/deprecation
692-
spanId: propCtxBeforeEnd.spanId,
693686
traceId: propCtxBeforeEnd.traceId,
694687
sampled: true,
695688
dsc: {
@@ -720,16 +713,13 @@ describe('browserTracingIntegration', () => {
720713

721714
const propCtxBeforeEnd = getCurrentScope().getPropagationContext();
722715
expect(propCtxBeforeEnd).toStrictEqual({
723-
spanId: expect.stringMatching(/[a-f0-9]{16}/),
724716
traceId: expect.stringMatching(/[a-f0-9]{32}/),
725717
});
726718

727719
navigationSpan!.end();
728720

729721
const propCtxAfterEnd = getCurrentScope().getPropagationContext();
730722
expect(propCtxAfterEnd).toStrictEqual({
731-
// eslint-disable-next-line deprecation/deprecation
732-
spanId: propCtxBeforeEnd.spanId,
733723
traceId: propCtxBeforeEnd.traceId,
734724
sampled: false,
735725
dsc: {

packages/core/src/currentScopes.ts

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

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

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

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

packages/core/src/scope.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import type {
2424
import { isPlainObject } from './utils-hoist/is';
2525
import { logger } from './utils-hoist/logger';
2626
import { uuid4 } from './utils-hoist/misc';
27-
import { generateSpanId, generateTraceId } from './utils-hoist/propagationContext';
27+
import { generateTraceId } from './utils-hoist/propagationContext';
2828
import { dateTimestampInSeconds } from './utils-hoist/time';
2929
import { merge } from './utils/merge';
3030
import { _getSpanForScope, _setSpanForScope } from './utils/spanOnScope';
@@ -166,7 +166,6 @@ export class Scope {
166166
this._sdkProcessingMetadata = {};
167167
this._propagationContext = {
168168
traceId: generateTraceId(),
169-
spanId: generateSpanId(),
170169
};
171170
}
172171

@@ -555,14 +554,8 @@ export class Scope {
555554
/**
556555
* Add propagation context to the scope, used for distributed tracing
557556
*/
558-
public setPropagationContext(
559-
context: Omit<PropagationContext, 'spanId'> & Partial<Pick<PropagationContext, 'spanId'>>,
560-
): this {
561-
this._propagationContext = {
562-
// eslint-disable-next-line deprecation/deprecation
563-
spanId: generateSpanId(),
564-
...context,
565-
};
557+
public setPropagationContext(context: PropagationContext): this {
558+
this._propagationContext = context;
566559
return this;
567560
}
568561

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
};

0 commit comments

Comments
 (0)