Skip to content

Commit a8e28eb

Browse files
authored
feat(v8): Remove deprecated span id fields (#11180)
ref #10100 Removes `span.spanId`, `span.traceId`, and `span.parentSpanId`.
1 parent 284e90d commit a8e28eb

File tree

8 files changed

+45
-98
lines changed

8 files changed

+45
-98
lines changed

dev-packages/node-integration-tests/suites/express/sentry-trace/baggage-header-out/server.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,11 @@ app.use(cors());
2828
app.get('/test/express', (_req, res) => {
2929
// eslint-disable-next-line deprecation/deprecation
3030
const transaction = Sentry.getCurrentScope().getTransaction();
31-
if (transaction) {
32-
// eslint-disable-next-line deprecation/deprecation
33-
transaction.traceId = '86f39e84263a4de99c326acab3bfe3bd';
34-
}
31+
const traceId = transaction?.spanContext().traceId;
3532
const headers = http.get('http://somewhere.not.sentry/').getHeaders();
36-
33+
if (traceId) {
34+
headers['baggage'] = (headers['baggage'] as string).replace(traceId, '__SENTRY_TRACE_ID__');
35+
}
3736
// Responding with the headers outgoing request headers back to the assertions.
3837
res.send({ test_data: headers });
3938
});

dev-packages/node-integration-tests/suites/express/sentry-trace/baggage-header-out/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ test('should attach a baggage header to an outgoing request.', async () => {
1616
host: 'somewhere.not.sentry',
1717
baggage:
1818
'sentry-environment=prod,sentry-release=1.0,sentry-public_key=public' +
19-
',sentry-trace_id=86f39e84263a4de99c326acab3bfe3bd,sentry-sample_rate=1,sentry-transaction=GET%20%2Ftest%2Fexpress' +
19+
',sentry-trace_id=__SENTRY_TRACE_ID__,sentry-sample_rate=1,sentry-transaction=GET%20%2Ftest%2Fexpress' +
2020
',sentry-sampled=true',
2121
},
2222
});

dev-packages/node-integration-tests/suites/express/sentry-trace/baggage-transaction-name/server.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,9 @@ app.use(cors());
3232
app.get('/test/express', (_req, res) => {
3333
// eslint-disable-next-line deprecation/deprecation
3434
const transaction = Sentry.getCurrentScope().getTransaction();
35-
if (transaction) {
36-
// eslint-disable-next-line deprecation/deprecation
37-
transaction.traceId = '86f39e84263a4de99c326acab3bfe3bd';
38-
transaction.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, 'route');
39-
}
40-
const headers = http.get('http://somewhere.not.sentry/').getHeaders();
35+
transaction?.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, 'route');
4136

37+
const headers = http.get('http://somewhere.not.sentry/').getHeaders();
4238
// Responding with the headers outgoing request headers back to the assertions.
4339
res.send({ test_data: headers });
4440
});

packages/core/src/tracing/sentrySpan.ts

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -97,56 +97,6 @@ export class SentrySpan implements Span {
9797
// This rule conflicts with another eslint rule :(
9898
/* eslint-disable @typescript-eslint/member-ordering */
9999

100-
/**
101-
* The ID of the trace.
102-
* @deprecated Use `spanContext().traceId` instead.
103-
*/
104-
public get traceId(): string {
105-
return this._traceId;
106-
}
107-
108-
/**
109-
* The ID of the trace.
110-
* @deprecated You cannot update the traceId of a span after span creation.
111-
*/
112-
public set traceId(traceId: string) {
113-
this._traceId = traceId;
114-
}
115-
116-
/**
117-
* The ID of the span.
118-
* @deprecated Use `spanContext().spanId` instead.
119-
*/
120-
public get spanId(): string {
121-
return this._spanId;
122-
}
123-
124-
/**
125-
* The ID of the span.
126-
* @deprecated You cannot update the spanId of a span after span creation.
127-
*/
128-
public set spanId(spanId: string) {
129-
this._spanId = spanId;
130-
}
131-
132-
/**
133-
* @inheritDoc
134-
*
135-
* @deprecated Use `startSpan` functions instead.
136-
*/
137-
public set parentSpanId(string) {
138-
this._parentSpanId = string;
139-
}
140-
141-
/**
142-
* @inheritDoc
143-
*
144-
* @deprecated Use `spanToJSON(span).parent_span_id` instead.
145-
*/
146-
public get parentSpanId(): string | undefined {
147-
return this._parentSpanId;
148-
}
149-
150100
/**
151101
* Was this span chosen to be sent as part of the sample?
152102
* @deprecated Use `isRecording()` instead.

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

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import { timestampInSeconds } from '@sentry/utils';
22
import { SentrySpan } from '../../../src/tracing/sentrySpan';
33
import { SPAN_STATUS_ERROR } from '../../../src/tracing/spanstatus';
4-
import { TRACE_FLAG_NONE, TRACE_FLAG_SAMPLED, spanToJSON, spanToTraceContext } from '../../../src/utils/spanUtils';
4+
import {
5+
TRACE_FLAG_NONE,
6+
TRACE_FLAG_SAMPLED,
7+
spanIsSampled,
8+
spanToJSON,
9+
spanToTraceContext,
10+
} from '../../../src/utils/spanUtils';
511

612
describe('SentrySpan', () => {
713
describe('name', () => {
@@ -25,9 +31,9 @@ describe('SentrySpan', () => {
2531
const span = new SentrySpan({ sampled: true });
2632
// eslint-disable-next-line deprecation/deprecation
2733
const span2 = span.startChild();
28-
expect((span2 as any).parentSpanId).toBe((span as any).spanId);
29-
expect((span2 as any).traceId).toBe((span as any).traceId);
30-
expect((span2 as any).sampled).toBe((span as any).sampled);
34+
expect(spanToJSON(span2).parent_span_id).toBe(span.spanContext().spanId);
35+
expect(span.spanContext().traceId).toBe(span.spanContext().traceId);
36+
expect(spanIsSampled(span2)).toBe(spanIsSampled(span));
3137
});
3238
});
3339

@@ -58,18 +64,23 @@ describe('SentrySpan', () => {
5864
});
5965

6066
test('with parent', () => {
61-
const spanA = new SentrySpan({ traceId: 'a', spanId: 'b' }) as any;
62-
const spanB = new SentrySpan({ traceId: 'c', spanId: 'd', sampled: false, parentSpanId: spanA.spanId });
67+
const spanA = new SentrySpan({ traceId: 'a', spanId: 'b' });
68+
const spanB = new SentrySpan({
69+
traceId: 'c',
70+
spanId: 'd',
71+
sampled: false,
72+
parentSpanId: spanA.spanContext().spanId,
73+
});
6374
const serialized = spanToJSON(spanB);
6475
expect(serialized).toHaveProperty('parent_span_id', 'b');
6576
expect(serialized).toHaveProperty('span_id', 'd');
6677
expect(serialized).toHaveProperty('trace_id', 'c');
6778
});
6879

6980
test('should drop all `undefined` values', () => {
70-
const spanA = new SentrySpan({ traceId: 'a', spanId: 'b' }) as any;
81+
const spanA = new SentrySpan({ traceId: 'a', spanId: 'b' });
7182
const spanB = new SentrySpan({
72-
parentSpanId: spanA.spanId,
83+
parentSpanId: spanA.spanContext().spanId,
7384
spanId: 'd',
7485
traceId: 'c',
7586
});

packages/node/test/handlers.test.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
getMainCarrier,
1010
mergeScopeData,
1111
setCurrentClient,
12+
spanIsSampled,
1213
spanToJSON,
1314
withScope,
1415
} from '@sentry/core';
@@ -289,7 +290,7 @@ describe('tracingHandler', () => {
289290

290291
sentryTracingMiddleware(req, res, next);
291292

292-
const transaction = (res as any).__sentry_transaction;
293+
const transaction = (res as any).__sentry_transaction as Transaction;
293294

294295
expect(getPropagationContext()).toEqual({
295296
traceId: '12312012123120121231201212312012',
@@ -300,9 +301,10 @@ describe('tracingHandler', () => {
300301
});
301302

302303
// since we have no tracesSampler defined, the default behavior (inherit if possible) applies
303-
expect(transaction.traceId).toEqual('12312012123120121231201212312012');
304-
expect(transaction.parentSpanId).toEqual('1121201211212012');
305-
expect(transaction.sampled).toEqual(false);
304+
expect(transaction.spanContext().traceId).toEqual('12312012123120121231201212312012');
305+
expect(spanToJSON(transaction).parent_span_id).toEqual('1121201211212012');
306+
expect(spanIsSampled(transaction)).toEqual(false);
307+
// eslint-disable-next-line deprecation/deprecation
306308
expect(transaction.metadata?.dynamicSamplingContext).toStrictEqual({});
307309
});
308310

@@ -322,12 +324,13 @@ describe('tracingHandler', () => {
322324
dsc: { version: '1.0', environment: 'production' },
323325
});
324326

325-
const transaction = (res as any).__sentry_transaction;
327+
const transaction = (res as any).__sentry_transaction as Transaction;
326328

327329
// since we have no tracesSampler defined, the default behavior (inherit if possible) applies
328-
expect(transaction.traceId).toEqual('12312012123120121231201212312012');
329-
expect(transaction.parentSpanId).toEqual('1121201211212012');
330-
expect(transaction.sampled).toEqual(true);
330+
expect(transaction.spanContext().traceId).toEqual('12312012123120121231201212312012');
331+
expect(spanToJSON(transaction).parent_span_id).toEqual('1121201211212012');
332+
expect(spanIsSampled(transaction)).toEqual(true);
333+
// eslint-disable-next-line deprecation/deprecation
331334
expect(transaction.metadata?.dynamicSamplingContext).toStrictEqual({ version: '1.0', environment: 'production' });
332335
});
333336

@@ -341,7 +344,8 @@ describe('tracingHandler', () => {
341344

342345
expect(getPropagationContext().dsc).toEqual({ version: '1.0', environment: 'production' });
343346

344-
const transaction = (res as any).__sentry_transaction;
347+
const transaction = (res as any).__sentry_transaction as Transaction;
348+
// eslint-disable-next-line deprecation/deprecation
345349
expect(transaction.metadata?.dynamicSamplingContext).toStrictEqual({ version: '1.0', environment: 'production' });
346350
});
347351

@@ -364,7 +368,7 @@ describe('tracingHandler', () => {
364368
it('puts its transaction on the response object', () => {
365369
sentryTracingMiddleware(req, res, next);
366370

367-
const transaction = (res as any).__sentry_transaction;
371+
const transaction = (res as any).__sentry_transaction as Transaction;
368372

369373
expect(transaction).toBeDefined();
370374

@@ -396,7 +400,7 @@ describe('tracingHandler', () => {
396400

397401
sentryTracingMiddleware(req, res, next);
398402

399-
const transaction = (res as any).__sentry_transaction;
403+
const transaction = (res as any).__sentry_transaction as Transaction;
400404

401405
expect(spanToJSON(transaction).description).toBe(`${method.toUpperCase()} ${path}`);
402406
});
@@ -406,7 +410,7 @@ describe('tracingHandler', () => {
406410

407411
sentryTracingMiddleware(req, res, next);
408412

409-
const transaction = (res as any).__sentry_transaction;
413+
const transaction = (res as any).__sentry_transaction as Transaction;
410414

411415
expect(spanToJSON(transaction).description).toBe(`${method.toUpperCase()} ${path}`);
412416
});
@@ -416,7 +420,7 @@ describe('tracingHandler', () => {
416420

417421
sentryTracingMiddleware(req, res, next);
418422

419-
const transaction = (res as any).__sentry_transaction;
423+
const transaction = (res as any).__sentry_transaction as Transaction;
420424

421425
expect(spanToJSON(transaction).description).toBe(`${method.toUpperCase()} ${path}`);
422426
});

packages/types/src/envelope.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@ import type { Profile } from './profiling';
88
import type { ReplayEvent, ReplayRecordingData } from './replay';
99
import type { SdkInfo } from './sdkinfo';
1010
import type { SerializedSession, Session, SessionAggregates } from './session';
11-
import type { Transaction } from './transaction';
1211

1312
// Based on: https://develop.sentry.dev/sdk/envelopes/
1413

1514
// Based on https://github.com/getsentry/relay/blob/b23b8d3b2360a54aaa4d19ecae0231201f31df5e/relay-sampling/src/lib.rs#L685-L707
1615
export type DynamicSamplingContext = {
17-
trace_id: Transaction['traceId'];
16+
trace_id: string;
1817
public_key: DsnComponents['publicKey'];
1918
sample_rate?: string;
2019
release?: string;

packages/types/src/transaction.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,7 @@ export interface TraceparentData {
5757
/**
5858
* Transaction "Class", inherits Span only has `setName`
5959
*/
60-
export interface Transaction extends Omit<TransactionContext, 'name' | 'op'>, Span {
61-
/**
62-
* The ID of the transaction.
63-
* @deprecated Use `spanContext().spanId` instead.
64-
*/
65-
spanId: string;
66-
67-
/**
68-
* The ID of the trace.
69-
* @deprecated Use `spanContext().traceId` instead.
70-
*/
71-
traceId: string;
72-
60+
export interface Transaction extends Omit<TransactionContext, 'name' | 'op' | 'spanId' | 'traceId'>, Span {
7361
/**
7462
* Was this transaction chosen to be sent as part of the sample?
7563
* @deprecated Use `spanIsSampled(transaction)` instead.

0 commit comments

Comments
 (0)