Skip to content

Commit 66b9609

Browse files
committed
fix: Remove circular dependency between span and transaction
1 parent 9b9c02a commit 66b9609

File tree

3 files changed

+33
-34
lines changed

3 files changed

+33
-34
lines changed

packages/tracing/src/idletransaction.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { Hub } from '@sentry/hub';
33
import { TransactionContext } from '@sentry/types';
44
import { logger, timestampWithMs } from '@sentry/utils';
55

6-
import { Span } from './span';
6+
import { Span, SpanRecorder } from './span';
77
import { SpanStatus } from './spanstatus';
8-
import { SpanRecorder, Transaction } from './transaction';
8+
import { Transaction } from './transaction';
99

1010
export const DEFAULT_IDLE_TIMEOUT = 1000;
1111

packages/tracing/src/span.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
// tslint:disable:max-classes-per-file
12
import { Span as SpanInterface, SpanContext } from '@sentry/types';
23
import { dropUndefinedKeys, timestampWithMs, uuid4 } from '@sentry/utils';
34

45
import { SpanStatus } from './spanstatus';
5-
import { SpanRecorder } from './transaction';
66

77
export const TRACEPARENT_REGEXP = new RegExp(
88
'^[ \\t]*' + // whitespace
@@ -12,6 +12,35 @@ export const TRACEPARENT_REGEXP = new RegExp(
1212
'[ \\t]*$', // whitespace
1313
);
1414

15+
/**
16+
* Keeps track of finished spans for a given transaction
17+
* @internal
18+
* @hideconstructor
19+
* @hidden
20+
*/
21+
export class SpanRecorder {
22+
private readonly _maxlen: number;
23+
public spans: Span[] = [];
24+
25+
public constructor(maxlen: number = 1000) {
26+
this._maxlen = maxlen;
27+
}
28+
29+
/**
30+
* This is just so that we don't run out of memory while recording a lot
31+
* of spans. At some point we just stop and flush out the start of the
32+
* trace tree (i.e.the first n spans with the smallest
33+
* start_timestamp).
34+
*/
35+
public add(span: Span): void {
36+
if (this.spans.length > this._maxlen) {
37+
span.spanRecorder = undefined;
38+
} else {
39+
this.spans.push(span);
40+
}
41+
}
42+
}
43+
1544
/**
1645
* Span contains all data about a span
1746
*/

packages/tracing/src/transaction.ts

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,8 @@
1-
// tslint:disable:max-classes-per-file
21
import { getCurrentHub, Hub } from '@sentry/hub';
32
import { TransactionContext } from '@sentry/types';
43
import { isInstanceOf, logger } from '@sentry/utils';
54

6-
import { Span as SpanClass } from './span';
7-
8-
/**
9-
* Keeps track of finished spans for a given transaction
10-
* @internal
11-
* @hideconstructor
12-
* @hidden
13-
*/
14-
export class SpanRecorder {
15-
private readonly _maxlen: number;
16-
public spans: SpanClass[] = [];
17-
18-
public constructor(maxlen: number = 1000) {
19-
this._maxlen = maxlen;
20-
}
21-
22-
/**
23-
* This is just so that we don't run out of memory while recording a lot
24-
* of spans. At some point we just stop and flush out the start of the
25-
* trace tree (i.e.the first n spans with the smallest
26-
* start_timestamp).
27-
*/
28-
public add(span: SpanClass): void {
29-
if (this.spans.length > this._maxlen) {
30-
span.spanRecorder = undefined;
31-
} else {
32-
this.spans.push(span);
33-
}
34-
}
35-
}
5+
import { Span as SpanClass, SpanRecorder } from './span';
366

377
/** JSDoc */
388
export class Transaction extends SpanClass {

0 commit comments

Comments
 (0)