Skip to content

Commit a08d370

Browse files
authored
ref: Remove spanRecorder and all related code (#10977)
This is now not used anymore, we use `getSpanDescendants()` internally now everywhere.
1 parent d3aa0af commit a08d370

File tree

10 files changed

+74
-112
lines changed

10 files changed

+74
-112
lines changed

packages/core/src/tracing/hubextensions.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ function _startTransaction(
4242
},
4343
...customSamplingContext,
4444
});
45-
if (transaction.isRecording()) {
46-
transaction.initSpanRecorder();
47-
}
4845
if (client) {
4946
client.emit('startTransaction', transaction);
5047
client.emit('spanStart', transaction);

packages/core/src/tracing/sentrySpan.ts

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -28,38 +28,6 @@ import {
2828
spanToTraceContext,
2929
} from '../utils/spanUtils';
3030

31-
/**
32-
* Keeps track of finished spans for a given transaction
33-
* @internal
34-
* @hideconstructor
35-
* @hidden
36-
*/
37-
export class SpanRecorder {
38-
public spans: SentrySpan[];
39-
40-
private readonly _maxlen: number;
41-
42-
public constructor(maxlen: number = 1000) {
43-
this._maxlen = maxlen;
44-
this.spans = [];
45-
}
46-
47-
/**
48-
* This is just so that we don't run out of memory while recording a lot
49-
* of spans. At some point we just stop and flush out the start of the
50-
* trace tree (i.e.the first n spans with the smallest
51-
* start_timestamp).
52-
*/
53-
public add(span: SentrySpan): void {
54-
if (this.spans.length > this._maxlen) {
55-
// eslint-disable-next-line deprecation/deprecation
56-
span.spanRecorder = undefined;
57-
} else {
58-
this.spans.push(span);
59-
}
60-
}
61-
}
62-
6331
/**
6432
* Span contains all data about a span
6533
*/
@@ -71,13 +39,6 @@ export class SentrySpan implements Span {
7139
// eslint-disable-next-line @typescript-eslint/no-explicit-any
7240
public data: { [key: string]: any };
7341

74-
/**
75-
* List of spans that were finalized
76-
*
77-
* @deprecated This property will no longer be public. Span recording will be handled internally.
78-
*/
79-
public spanRecorder?: SpanRecorder;
80-
8142
/**
8243
* @inheritDoc
8344
* @deprecated Use top level `Sentry.getRootSpan()` instead
@@ -278,14 +239,6 @@ export class SentrySpan implements Span {
278239
traceId: this._traceId,
279240
});
280241

281-
// eslint-disable-next-line deprecation/deprecation
282-
childSpan.spanRecorder = this.spanRecorder;
283-
// eslint-disable-next-line deprecation/deprecation
284-
if (childSpan.spanRecorder) {
285-
// eslint-disable-next-line deprecation/deprecation
286-
childSpan.spanRecorder.add(childSpan);
287-
}
288-
289242
// To allow for interoperability we track the children of a span twice: Once with the span recorder (old) once with
290243
// the `addChildSpanToSpan`. Eventually we will only use `addChildSpanToSpan` and drop the span recorder.
291244
// To ensure interoperability with the `startSpan` API, `addChildSpanToSpan` is also called here.

packages/core/src/tracing/transaction.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { getMetricSummaryJsonForSpan } from '../metrics/metric-summary';
2121
import { SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '../semanticAttributes';
2222
import { getSpanDescendants, spanTimeInputToSeconds, spanToJSON, spanToTraceContext } from '../utils/spanUtils';
2323
import { getDynamicSamplingContextFromSpan } from './dynamicSamplingContext';
24-
import { SentrySpan, SpanRecorder } from './sentrySpan';
24+
import { SentrySpan } from './sentrySpan';
2525
import { getCapturedScopesOnSpan } from './utils';
2626

2727
/** JSDoc */
@@ -128,20 +128,6 @@ export class Transaction extends SentrySpan implements TransactionInterface {
128128
return this;
129129
}
130130

131-
/**
132-
* Attaches SpanRecorder to the span itself
133-
* @param maxlen maximum number of spans that can be recorded
134-
*/
135-
public initSpanRecorder(maxlen: number = 1000): void {
136-
// eslint-disable-next-line deprecation/deprecation
137-
if (!this.spanRecorder) {
138-
// eslint-disable-next-line deprecation/deprecation
139-
this.spanRecorder = new SpanRecorder(maxlen);
140-
}
141-
// eslint-disable-next-line deprecation/deprecation
142-
this.spanRecorder.add(this);
143-
}
144-
145131
/**
146132
* Set the context of a transaction event.
147133
* @deprecated Use either `.setAttribute()`, or set the context on the scope before creating the transaction.

packages/node/test/handlers.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,6 @@ describe('tracingHandler', () => {
461461
it('waits to finish transaction until all spans are finished, even though `transaction.end()` is registered on `res.finish` event first', done => {
462462
// eslint-disable-next-line deprecation/deprecation
463463
const transaction = new Transaction({ name: 'mockTransaction', sampled: true });
464-
transaction.initSpanRecorder();
465464
// eslint-disable-next-line deprecation/deprecation
466465
const span = transaction.startChild({
467466
name: 'reallyCoolHandler',

packages/node/test/integrations/http.test.ts

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as http from 'http';
22
import * as https from 'https';
3-
import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core';
4-
import type { Hub, SentrySpan } from '@sentry/core';
3+
import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, getSpanDescendants } from '@sentry/core';
4+
import type { Hub } from '@sentry/core';
55
import { getCurrentHub, getIsolationScope, setCurrentClient } from '@sentry/core';
66
import { Transaction } from '@sentry/core';
77
import { getCurrentScope, setUser, spanToJSON, startInactiveSpan } from '@sentry/core';
@@ -81,12 +81,10 @@ describe('tracing', () => {
8181
nock('http://dogs.are.great').get('/').reply(200);
8282

8383
const transaction = createTransactionOnScope();
84-
// eslint-disable-next-line deprecation/deprecation
85-
const spans = (transaction as unknown as SentrySpan).spanRecorder?.spans as SentrySpan[];
8684

8785
http.get('http://dogs.are.great/');
8886

89-
expect(spans.length).toEqual(2);
87+
const spans = getSpanDescendants(transaction);
9088

9189
// our span is at index 1 because the transaction itself is at index 0
9290
expect(spanToJSON(spans[1]).description).toEqual('GET http://dogs.are.great/');
@@ -97,11 +95,11 @@ describe('tracing', () => {
9795
nock('http://squirrelchasers.ingest.sentry.io').get('/api/12312012/store/').reply(200);
9896

9997
const transaction = createTransactionOnScope();
100-
// eslint-disable-next-line deprecation/deprecation
101-
const spans = (transaction as unknown as SentrySpan).spanRecorder?.spans as SentrySpan[];
10298

10399
http.get('http://squirrelchasers.ingest.sentry.io/api/12312012/store/');
104100

101+
const spans = getSpanDescendants(transaction);
102+
105103
// only the transaction itself should be there
106104
expect(spans.length).toEqual(1);
107105
expect(spanToJSON(spans[0]).description).toEqual('dogpark');
@@ -263,11 +261,11 @@ describe('tracing', () => {
263261
nock('http://dogs.are.great').get('/spaniel?tail=wag&cute=true#learn-more').reply(200);
264262

265263
const transaction = createTransactionOnScope();
266-
// eslint-disable-next-line deprecation/deprecation
267-
const spans = (transaction as unknown as SentrySpan).spanRecorder?.spans as SentrySpan[];
268264

269265
http.get('http://dogs.are.great/spaniel?tail=wag&cute=true#learn-more');
270266

267+
const spans = getSpanDescendants(transaction);
268+
271269
expect(spans.length).toEqual(2);
272270

273271
// our span is at index 1 because the transaction itself is at index 0
@@ -286,11 +284,11 @@ describe('tracing', () => {
286284
nock('http://dogs.are.great').get('/spaniel?tail=wag&cute=true#learn-more').reply(200);
287285

288286
const transaction = createTransactionOnScope();
289-
// eslint-disable-next-line deprecation/deprecation
290-
const spans = (transaction as unknown as SentrySpan).spanRecorder?.spans as SentrySpan[];
291287

292288
http.request({ method: 'GET', host: 'dogs.are.great', path: '/spaniel?tail=wag&cute=true#learn-more' });
293289

290+
const spans = getSpanDescendants(transaction);
291+
294292
expect(spans.length).toEqual(2);
295293

296294
const spanAttributes = spanToJSON(spans[1]).data || {};
@@ -314,11 +312,11 @@ describe('tracing', () => {
314312
nock(`http://${auth}@dogs.are.great`).get('/').reply(200);
315313

316314
const transaction = createTransactionOnScope();
317-
// eslint-disable-next-line deprecation/deprecation
318-
const spans = (transaction as unknown as SentrySpan).spanRecorder?.spans as SentrySpan[];
319315

320316
http.get(`http://${auth}@dogs.are.great/`);
321317

318+
const spans = getSpanDescendants(transaction);
319+
322320
expect(spans.length).toEqual(2);
323321

324322
// our span is at index 1 because the transaction itself is at index 0
@@ -374,11 +372,11 @@ describe('tracing', () => {
374372
);
375373

376374
const transaction = createTransactionAndPutOnScope();
377-
// eslint-disable-next-line deprecation/deprecation
378-
const spans = (transaction as unknown as SentrySpan).spanRecorder?.spans as SentrySpan[];
379375

380376
const request = http.get(url);
381377

378+
const spans = getSpanDescendants(transaction);
379+
382380
// There should be no http spans
383381
const httpSpans = spans.filter(span => spanToJSON(span).op?.startsWith('http'));
384382
expect(httpSpans.length).toBe(0);
@@ -483,11 +481,11 @@ describe('tracing', () => {
483481
);
484482

485483
const transaction = createTransactionAndPutOnScope();
486-
// eslint-disable-next-line deprecation/deprecation
487-
const spans = (transaction as unknown as SentrySpan).spanRecorder?.spans as SentrySpan[];
488484

489485
const request = http.get(url);
490486

487+
const spans = getSpanDescendants(transaction);
488+
491489
// There should be no http spans
492490
const httpSpans = spans.filter(span => spanToJSON(span).op?.startsWith('http'));
493491
expect(httpSpans.length).toBe(0);

packages/node/test/integrations/undici.test.ts

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
getCurrentScope,
77
getIsolationScope,
88
getMainCarrier,
9+
getSpanDescendants,
910
setCurrentClient,
1011
spanToJSON,
1112
startSpan,
@@ -125,8 +126,7 @@ conditionalTest({ min: 16 })('Undici integration', () => {
125126
await fetch(request, requestInit);
126127

127128
expect(outerSpan).toBeInstanceOf(Transaction);
128-
// eslint-disable-next-line deprecation/deprecation
129-
const spans = (outerSpan as Transaction).spanRecorder?.spans || [];
129+
const spans = getSpanDescendants(outerSpan);
130130

131131
expect(spans.length).toBe(2);
132132

@@ -144,8 +144,7 @@ conditionalTest({ min: 16 })('Undici integration', () => {
144144
}
145145

146146
expect(outerSpan).toBeInstanceOf(Transaction);
147-
// eslint-disable-next-line deprecation/deprecation
148-
const spans = (outerSpan as Transaction).spanRecorder?.spans || [];
147+
const spans = getSpanDescendants(outerSpan);
149148

150149
expect(spans.length).toBe(2);
151150

@@ -165,8 +164,7 @@ conditionalTest({ min: 16 })('Undici integration', () => {
165164
}
166165

167166
expect(outerSpan).toBeInstanceOf(Transaction);
168-
// eslint-disable-next-line deprecation/deprecation
169-
const spans = (outerSpan as Transaction).spanRecorder?.spans || [];
167+
const spans = getSpanDescendants(outerSpan);
170168

171169
expect(spans.length).toBe(2);
172170

@@ -187,8 +185,7 @@ conditionalTest({ min: 16 })('Undici integration', () => {
187185
}
188186

189187
expect(outerSpan).toBeInstanceOf(Transaction);
190-
// eslint-disable-next-line deprecation/deprecation
191-
const spans = (outerSpan as Transaction).spanRecorder?.spans || [];
188+
const spans = getSpanDescendants(outerSpan);
192189

193190
expect(spans.length).toBe(1);
194191
});
@@ -207,18 +204,17 @@ conditionalTest({ min: 16 })('Undici integration', () => {
207204
it('does create a span if `shouldCreateSpanForRequest` is defined', async () => {
208205
await startSpan({ name: 'outer-span' }, async outerSpan => {
209206
expect(outerSpan).toBeInstanceOf(Transaction);
210-
// eslint-disable-next-line deprecation/deprecation
211-
const spans = (outerSpan as Transaction).spanRecorder?.spans || [];
207+
expect(getSpanDescendants(outerSpan).length).toBe(1);
212208

213209
const undoPatch = patchUndici({ shouldCreateSpanForRequest: url => url.includes('yes') });
214210

215211
await fetch('http://localhost:18100/no', { method: 'POST' });
216212

217-
expect(spans.length).toBe(1);
213+
expect(getSpanDescendants(outerSpan).length).toBe(1);
218214

219215
await fetch('http://localhost:18100/yes', { method: 'POST' });
220216

221-
expect(spans.length).toBe(2);
217+
expect(getSpanDescendants(outerSpan).length).toBe(2);
222218

223219
undoPatch();
224220
});
@@ -232,8 +228,7 @@ conditionalTest({ min: 16 })('Undici integration', () => {
232228
await withIsolationScope(async () => {
233229
await startSpan({ name: 'outer-span' }, async outerSpan => {
234230
expect(outerSpan).toBeInstanceOf(Transaction);
235-
// eslint-disable-next-line deprecation/deprecation
236-
const spans = (outerSpan as Transaction).spanRecorder?.spans || [];
231+
const spans = getSpanDescendants(outerSpan);
237232

238233
await fetch('http://localhost:18100', { method: 'POST' });
239234

@@ -307,8 +302,7 @@ conditionalTest({ min: 16 })('Undici integration', () => {
307302

308303
await startSpan({ name: 'outer-span' }, async outerSpan => {
309304
expect(outerSpan).toBeInstanceOf(Transaction);
310-
// eslint-disable-next-line deprecation/deprecation
311-
const spans = (outerSpan as Transaction).spanRecorder?.spans || [];
305+
const spans = getSpanDescendants(outerSpan);
312306

313307
expect(spans.length).toBe(1);
314308

packages/node/test/performance.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ describe('startSpan()', () => {
8181

8282
const transactionEvent = await transactionEventPromise;
8383

84+
expect(transactionEvent.spans).toHaveLength(1);
8485
expect(transactionEvent.spans?.[0].description).toBe('second');
8586
});
8687
});

packages/opentelemetry/src/custom/transaction.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ export function startTransaction(hub: HubInterface, transactionContext: Transact
1212

1313
// eslint-disable-next-line deprecation/deprecation
1414
const transaction = new Transaction(transactionContext, hub as Hub);
15-
// Since we do not do sampling here, we assume that this is _always_ sampled
16-
// Any sampling decision happens in OpenTelemetry's sampler
17-
transaction.initSpanRecorder();
1815

1916
if (client) {
2017
client.emit('startTransaction', transaction);

packages/opentelemetry/test/custom/transaction.test.ts

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import { Transaction, getCurrentHub, setCurrentClient, spanToJSON } from '@sentry/core';
1+
import {
2+
Transaction,
3+
getCurrentHub,
4+
getSpanDescendants,
5+
setCurrentClient,
6+
spanIsSampled,
7+
spanToJSON,
8+
} from '@sentry/core';
29
import { startTransaction } from '../../src/custom/transaction';
310
import { TestClient, getDefaultTestClientOptions } from '../helpers/TestClient';
411

@@ -7,7 +14,7 @@ describe('startTranscation', () => {
714
jest.resetAllMocks();
815
});
916

10-
it('creates a Transaction', () => {
17+
it('creates an unsampled transaction', () => {
1118
const client = new TestClient(getDefaultTestClientOptions());
1219
// eslint-disable-next-line deprecation/deprecation
1320
const hub = getCurrentHub();
@@ -18,10 +25,37 @@ describe('startTranscation', () => {
1825

1926
expect(transaction).toBeInstanceOf(Transaction);
2027
expect(transaction['_sampled']).toBe(undefined);
28+
expect(spanIsSampled(transaction)).toBe(false);
29+
// unsampled span is filtered out here
30+
expect(getSpanDescendants(transaction)).toHaveLength(0);
2131
// eslint-disable-next-line deprecation/deprecation
22-
expect(transaction.spanRecorder).toBeDefined();
32+
expect(transaction.metadata).toEqual({
33+
spanMetadata: {},
34+
});
35+
36+
expect(spanToJSON(transaction)).toEqual(
37+
expect.objectContaining({
38+
origin: 'manual',
39+
span_id: expect.any(String),
40+
start_timestamp: expect.any(Number),
41+
trace_id: expect.any(String),
42+
}),
43+
);
44+
});
45+
46+
it('creates a sampled transaction', () => {
47+
const client = new TestClient(getDefaultTestClientOptions());
2348
// eslint-disable-next-line deprecation/deprecation
24-
expect(transaction.spanRecorder?.spans).toHaveLength(1);
49+
const hub = getCurrentHub();
50+
setCurrentClient(client);
51+
client.init();
52+
53+
const transaction = startTransaction(hub, { name: 'test', sampled: true });
54+
55+
expect(transaction).toBeInstanceOf(Transaction);
56+
expect(transaction['_sampled']).toBe(true);
57+
expect(spanIsSampled(transaction)).toBe(true);
58+
expect(getSpanDescendants(transaction)).toHaveLength(1);
2559
// eslint-disable-next-line deprecation/deprecation
2660
expect(transaction.metadata).toEqual({
2761
spanMetadata: {},

0 commit comments

Comments
 (0)