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

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/core/test/lib/feedback.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ describe('captureFeedback', () => {
260260

261261
getCurrentScope().setPropagationContext({
262262
traceId,
263-
spanId,
263+
parentSpanId: spanId,
264264
dsc,
265265
});
266266

@@ -290,7 +290,8 @@ describe('captureFeedback', () => {
290290
contexts: {
291291
trace: {
292292
trace_id: traceId,
293-
span_id: spanId,
293+
parent_span_id: spanId,
294+
span_id: expect.stringMatching(/[a-f0-9]{16}/),
294295
},
295296
feedback: {
296297
message: 'test',

packages/core/test/lib/prepareEvent.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ describe('parseEventHintOrCaptureContext', () => {
156156
fingerprint: ['xx', 'yy'],
157157
propagationContext: {
158158
traceId: 'xxx',
159-
spanId: 'yyy',
160159
},
161160
};
162161

@@ -247,7 +246,7 @@ describe('prepareEvent', () => {
247246
tags: { tag1: 'aa', tag2: 'aa' },
248247
extra: { extra1: 'aa', extra2: 'aa' },
249248
contexts: { os: { name: 'os1' }, culture: { display_name: 'name1' } },
250-
propagationContext: { spanId: '1', traceId: '1' },
249+
propagationContext: { traceId: '1' },
251250
fingerprint: ['aa'],
252251
});
253252
scope.addBreadcrumb(breadcrumb1);

packages/core/test/lib/scope.test.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ describe('Scope', () => {
3232
eventProcessors: [],
3333
propagationContext: {
3434
traceId: expect.any(String),
35-
spanId: expect.any(String),
3635
},
3736
sdkProcessingMetadata: {},
3837
});
@@ -58,7 +57,6 @@ describe('Scope', () => {
5857
eventProcessors: [],
5958
propagationContext: {
6059
traceId: expect.any(String),
61-
spanId: expect.any(String),
6260
},
6361
sdkProcessingMetadata: {},
6462
});
@@ -92,7 +90,6 @@ describe('Scope', () => {
9290
eventProcessors: [],
9391
propagationContext: {
9492
traceId: expect.any(String),
95-
spanId: expect.any(String),
9693
},
9794
sdkProcessingMetadata: {},
9895
});
@@ -104,7 +101,6 @@ describe('Scope', () => {
104101

105102
expect(scope.getScopeData().propagationContext).toEqual({
106103
traceId: expect.any(String),
107-
spanId: expect.any(String),
108104
sampled: undefined,
109105
dsc: undefined,
110106
parentSpanId: undefined,
@@ -232,13 +228,11 @@ describe('Scope', () => {
232228
const oldPropagationContext = scope.getPropagationContext();
233229
scope.setPropagationContext({
234230
traceId: '86f39e84263a4de99c326acab3bfe3bd',
235-
spanId: '6e0c63257de34c92',
236231
sampled: true,
237232
});
238233
expect(scope.getPropagationContext()).not.toEqual(oldPropagationContext);
239234
expect(scope.getPropagationContext()).toEqual({
240235
traceId: '86f39e84263a4de99c326acab3bfe3bd',
241-
spanId: '6e0c63257de34c92',
242236
sampled: true,
243237
});
244238
});
@@ -298,7 +292,6 @@ describe('Scope', () => {
298292
expect(scope['_extra']).toEqual({});
299293
expect(scope['_propagationContext']).toEqual({
300294
traceId: expect.any(String),
301-
spanId: expect.any(String),
302295
sampled: undefined,
303296
});
304297
expect(scope['_propagationContext']).not.toEqual(oldPropagationContext);
@@ -426,7 +419,6 @@ describe('Scope', () => {
426419
user: { id: '42' },
427420
propagationContext: {
428421
traceId: '8949daf83f4a4a70bee4c1eb9ab242ed',
429-
spanId: 'a024ad8fea82680e',
430422
sampled: true,
431423
},
432424
};
@@ -453,7 +445,6 @@ describe('Scope', () => {
453445
expect(updatedScope._fingerprint).toEqual(['bar']);
454446
expect(updatedScope._propagationContext).toEqual({
455447
traceId: '8949daf83f4a4a70bee4c1eb9ab242ed',
456-
spanId: 'a024ad8fea82680e',
457448
sampled: true,
458449
});
459450
});
@@ -502,7 +493,7 @@ describe('Scope', () => {
502493
tags: { tag1: 'aa', tag2: 'aa' },
503494
extra: { extra1: 'aa', extra2: 'aa' },
504495
contexts: { os: { name: 'os1' }, culture: { display_name: 'name1' } },
505-
propagationContext: { spanId: '1', traceId: '1' },
496+
propagationContext: { traceId: '1' },
506497
fingerprint: ['aa'],
507498
});
508499
scope.addBreadcrumb(breadcrumb1);

packages/core/test/lib/tracing/trace.test.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,6 @@ describe('startSpan', () => {
396396
withScope(scope => {
397397
scope.setPropagationContext({
398398
traceId: '99999999999999999999999999999999',
399-
spanId: '1212121212121212',
400399
dsc: {},
401400
parentSpanId: '4242424242424242',
402401
});
@@ -829,7 +828,6 @@ describe('startSpanManual', () => {
829828
withScope(scope => {
830829
scope.setPropagationContext({
831830
traceId: '99999999999999999999999999999991',
832-
spanId: '1212121212121212',
833831
dsc: {},
834832
parentSpanId: '4242424242424242',
835833
});
@@ -1147,7 +1145,6 @@ describe('startInactiveSpan', () => {
11471145
withScope(scope => {
11481146
scope.setPropagationContext({
11491147
traceId: '99999999999999999999999999999991',
1150-
spanId: '1212121212121212',
11511148
dsc: {},
11521149
parentSpanId: '4242424242424242',
11531150
});
@@ -1329,7 +1326,6 @@ describe('continueTrace', () => {
13291326

13301327
expect(scope.getPropagationContext()).toEqual({
13311328
sampled: undefined,
1332-
spanId: expect.any(String),
13331329
traceId: expect.any(String),
13341330
});
13351331

@@ -1351,7 +1347,6 @@ describe('continueTrace', () => {
13511347
dsc: {}, // DSC should be an empty object (frozen), because there was an incoming trace
13521348
sampled: false,
13531349
parentSpanId: '1121201211212012',
1354-
spanId: expect.any(String),
13551350
traceId: '12312012123120121231201212312012',
13561351
});
13571352

@@ -1376,7 +1371,6 @@ describe('continueTrace', () => {
13761371
},
13771372
sampled: true,
13781373
parentSpanId: '1121201211212012',
1379-
spanId: expect.any(String),
13801374
traceId: '12312012123120121231201212312012',
13811375
});
13821376

@@ -1401,7 +1395,6 @@ describe('continueTrace', () => {
14011395
},
14021396
sampled: true,
14031397
parentSpanId: '1121201211212012',
1404-
spanId: expect.any(String),
14051398
traceId: '12312012123120121231201212312012',
14061399
});
14071400

0 commit comments

Comments
 (0)