Skip to content

Commit 412dd69

Browse files
committed
avoid circular dependency check
1 parent d5cbc78 commit 412dd69

File tree

9 files changed

+59
-59
lines changed

9 files changed

+59
-59
lines changed

packages/core/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ export {
9090
spanToJSON,
9191
spanIsSampled,
9292
spanToTraceContext,
93+
getSpanDescendants,
9394
} from './utils/spanUtils';
9495
export { getRootSpan } from './utils/getRootSpan';
9596
export { applySdkMetadata } from './utils/sdkMetadata';

packages/core/src/tracing/idleSpan.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import { getClient, getCurrentScope } from '../currentScopes';
44

55
import { DEBUG_BUILD } from '../debug-build';
66
import { hasTracingEnabled } from '../utils/hasTracingEnabled';
7-
import { spanToJSON } from '../utils/spanUtils';
7+
import { getSpanDescendants, removeChildSpanFromSpan, spanToJSON } from '../utils/spanUtils';
88
import { SentryNonRecordingSpan } from './sentryNonRecordingSpan';
99
import { SPAN_STATUS_ERROR } from './spanstatus';
1010
import { startInactiveSpan } from './trace';
11-
import { getActiveSpan, getSpanDescendants, removeChildSpanFromSpan } from './utils';
11+
import { getActiveSpan } from './utils';
1212

1313
export const TRACING_DEFAULTS = {
1414
idleTimeout: 1_000,

packages/core/src/tracing/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export { SentrySpan } from './sentrySpan';
55
export { SentryNonRecordingSpan } from './sentryNonRecordingSpan';
66
export { Transaction } from './transaction';
77
// eslint-disable-next-line deprecation/deprecation
8-
export { getActiveTransaction, getActiveSpan, getSpanDescendants } from './utils';
8+
export { getActiveTransaction, getActiveSpan } from './utils';
99
export {
1010
setHttpStatus,
1111
getSpanStatusFromHttpCode,

packages/core/src/tracing/sentrySpan.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ import { getRootSpan } from '../utils/getRootSpan';
2222
import {
2323
TRACE_FLAG_NONE,
2424
TRACE_FLAG_SAMPLED,
25+
addChildSpanToSpan,
2526
getStatusMessage,
2627
spanTimeInputToSeconds,
2728
spanToJSON,
2829
spanToTraceContext,
2930
} from '../utils/spanUtils';
30-
import { addChildSpanToSpan } from './utils';
3131

3232
/**
3333
* Keeps track of finished spans for a given transaction

packages/core/src/tracing/trace.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import { DEBUG_BUILD } from '../debug-build';
77
import { getCurrentHub } from '../hub';
88
import { handleCallbackErrors } from '../utils/handleCallbackErrors';
99
import { hasTracingEnabled } from '../utils/hasTracingEnabled';
10-
import { spanIsSampled, spanTimeInputToSeconds, spanToJSON } from '../utils/spanUtils';
10+
import { addChildSpanToSpan, spanIsSampled, spanTimeInputToSeconds, spanToJSON } from '../utils/spanUtils';
1111
import { getDynamicSamplingContextFromSpan } from './dynamicSamplingContext';
1212
import { SentryNonRecordingSpan } from './sentryNonRecordingSpan';
1313
import type { SentrySpan } from './sentrySpan';
1414
import { SPAN_STATUS_ERROR } from './spanstatus';
15-
import { addChildSpanToSpan, getActiveSpan, setCapturedScopesOnSpan } from './utils';
15+
import { getActiveSpan, setCapturedScopesOnSpan } from './utils';
1616

1717
/**
1818
* Wraps a function with a transaction/span and finishes the span after the function is done.

packages/core/src/tracing/transaction.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ import { DEBUG_BUILD } from '../debug-build';
1919
import { getCurrentHub } from '../hub';
2020
import { getMetricSummaryJsonForSpan } from '../metrics/metric-summary';
2121
import { SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '../semanticAttributes';
22-
import { spanTimeInputToSeconds, spanToJSON, spanToTraceContext } from '../utils/spanUtils';
22+
import { getSpanDescendants, spanTimeInputToSeconds, spanToJSON, spanToTraceContext } from '../utils/spanUtils';
2323
import { getDynamicSamplingContextFromSpan } from './dynamicSamplingContext';
2424
import { SentrySpan, SpanRecorder } from './sentrySpan';
25-
import { getCapturedScopesOnSpan, getSpanDescendants } from './utils';
25+
import { getCapturedScopesOnSpan } from './utils';
2626

2727
/** JSDoc */
2828
export class Transaction extends SentrySpan implements TransactionInterface {

packages/core/src/tracing/utils.ts

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { getCurrentScope } from '../currentScopes';
55

66
import type { Hub } from '../hub';
77
import { getCurrentHub } from '../hub';
8-
import { spanIsSampled } from '../utils/spanUtils';
98

109
/**
1110
* Grabs active transaction off scope.
@@ -32,55 +31,6 @@ export function getActiveSpan(): Span | undefined {
3231
return getCurrentScope().getSpan();
3332
}
3433

35-
const CHILD_SPANS_FIELD = '_sentryChildSpans';
36-
37-
type SpanWithPotentialChildren = Span & {
38-
[CHILD_SPANS_FIELD]?: Set<Span>;
39-
};
40-
41-
/**
42-
* Adds an opaque child span reference to a span.
43-
*/
44-
export function addChildSpanToSpan(span: SpanWithPotentialChildren, childSpan: Span): void {
45-
if (span[CHILD_SPANS_FIELD] && span[CHILD_SPANS_FIELD].size < 1000) {
46-
span[CHILD_SPANS_FIELD].add(childSpan);
47-
} else {
48-
span[CHILD_SPANS_FIELD] = new Set([childSpan]);
49-
}
50-
}
51-
52-
/** This is only used internally by Idle Spans. */
53-
export function removeChildSpanFromSpan(span: SpanWithPotentialChildren, childSpan: Span): void {
54-
if (span[CHILD_SPANS_FIELD]) {
55-
span[CHILD_SPANS_FIELD].delete(childSpan);
56-
}
57-
}
58-
59-
/**
60-
* Returns an array of the given span and all of its descendants.
61-
*/
62-
export function getSpanDescendants(span: SpanWithPotentialChildren): Span[] {
63-
const resultSet = new Set<Span>();
64-
65-
function addSpanChildren(span: SpanWithPotentialChildren): void {
66-
// This exit condition is required to not infinitely loop in case of a circular dependency.
67-
if (resultSet.has(span)) {
68-
return;
69-
// We want to ignore unsampled spans (e.g. non recording spans)
70-
} else if (spanIsSampled(span)) {
71-
resultSet.add(span);
72-
const childSpans = span[CHILD_SPANS_FIELD] ? Array.from(span[CHILD_SPANS_FIELD]) : [];
73-
for (const childSpan of childSpans) {
74-
addSpanChildren(childSpan);
75-
}
76-
}
77-
}
78-
79-
addSpanChildren(span);
80-
81-
return Array.from(resultSet);
82-
}
83-
8434
const SCOPE_ON_START_SPAN_FIELD = '_sentryScope';
8535
const ISOLATION_SCOPE_ON_START_SPAN_FIELD = '_sentryIsolationScope';
8636

packages/core/src/utils/spanUtils.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,52 @@ export function getStatusMessage(status: SpanStatus | undefined): string | undef
168168

169169
return status.message || 'unknown_error';
170170
}
171+
172+
const CHILD_SPANS_FIELD = '_sentryChildSpans';
173+
174+
type SpanWithPotentialChildren = Span & {
175+
[CHILD_SPANS_FIELD]?: Set<Span>;
176+
};
177+
178+
/**
179+
* Adds an opaque child span reference to a span.
180+
*/
181+
export function addChildSpanToSpan(span: SpanWithPotentialChildren, childSpan: Span): void {
182+
if (span[CHILD_SPANS_FIELD] && span[CHILD_SPANS_FIELD].size < 1000) {
183+
span[CHILD_SPANS_FIELD].add(childSpan);
184+
} else {
185+
span[CHILD_SPANS_FIELD] = new Set([childSpan]);
186+
}
187+
}
188+
189+
/** This is only used internally by Idle Spans. */
190+
export function removeChildSpanFromSpan(span: SpanWithPotentialChildren, childSpan: Span): void {
191+
if (span[CHILD_SPANS_FIELD]) {
192+
span[CHILD_SPANS_FIELD].delete(childSpan);
193+
}
194+
}
195+
196+
/**
197+
* Returns an array of the given span and all of its descendants.
198+
*/
199+
export function getSpanDescendants(span: SpanWithPotentialChildren): Span[] {
200+
const resultSet = new Set<Span>();
201+
202+
function addSpanChildren(span: SpanWithPotentialChildren): void {
203+
// This exit condition is required to not infinitely loop in case of a circular dependency.
204+
if (resultSet.has(span)) {
205+
return;
206+
// We want to ignore unsampled spans (e.g. non recording spans)
207+
} else if (spanIsSampled(span)) {
208+
resultSet.add(span);
209+
const childSpans = span[CHILD_SPANS_FIELD] ? Array.from(span[CHILD_SPANS_FIELD]) : [];
210+
for (const childSpan of childSpans) {
211+
addSpanChildren(childSpan);
212+
}
213+
}
214+
}
215+
216+
addSpanChildren(span);
217+
218+
return Array.from(resultSet);
219+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
startSpanManual,
2121
} from '../../../src/tracing';
2222
import { SentryNonRecordingSpan } from '../../../src/tracing/sentryNonRecordingSpan';
23-
import { getSpanDescendants } from '../../../src/tracing/utils';
23+
import { getSpanDescendants } from '../../../src/utils/spanUtils';
2424
import { TestClient, getDefaultTestClientOptions } from '../../mocks/client';
2525

2626
beforeAll(() => {

0 commit comments

Comments
 (0)