Skip to content

Commit 64a11a4

Browse files
committed
fix circular dep check
1 parent 8cca930 commit 64a11a4

File tree

7 files changed

+37
-34
lines changed

7 files changed

+37
-34
lines changed

packages/core/src/scope.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { dateTimestampInSeconds, isPlainObject, logger, uuid4 } from '@sentry/ut
2626

2727
import { updateSession } from './session';
2828
import type { SentrySpan } from './tracing/sentrySpan';
29-
import { _getSpanForScope, _setSpanForScope } from './utils/spanUtils';
29+
import { _getSpanForScope, _setSpanForScope } from './utils/spanOnScope';
3030

3131
/**
3232
* Default value for maximum number of breadcrumbs added to an event.

packages/core/src/server-runtime-client.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ import {
2424
getDynamicSamplingContextFromClient,
2525
getDynamicSamplingContextFromSpan,
2626
} from './tracing';
27-
import { _getSpanForScope, getRootSpan, spanToTraceContext } from './utils/spanUtils';
27+
import { _getSpanForScope } from './utils/spanOnScope';
28+
import { getRootSpan, spanToTraceContext } from './utils/spanUtils';
2829

2930
export interface ServerRuntimeClientOptions extends ClientOptions<BaseTransportOptions> {
3031
platform?: string;

packages/core/src/tracing/idleSpan.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { getClient, getCurrentScope } from '../currentScopes';
55
import { DEBUG_BUILD } from '../debug-build';
66
import { SEMANTIC_ATTRIBUTE_SENTRY_IDLE_SPAN_FINISH_REASON } from '../semanticAttributes';
77
import { hasTracingEnabled } from '../utils/hasTracingEnabled';
8+
import { _setSpanForScope } from '../utils/spanOnScope';
89
import {
9-
_setSpanForScope,
1010
getActiveSpan,
1111
getSpanDescendants,
1212
removeChildSpanFromSpan,

packages/core/src/tracing/trace.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ import { getClient, getCurrentScope, getIsolationScope, withScope } from '../cur
88
import { getAsyncContextStrategy, getCurrentHub } from '../hub';
99
import { handleCallbackErrors } from '../utils/handleCallbackErrors';
1010
import { hasTracingEnabled } from '../utils/hasTracingEnabled';
11+
import { _getSpanForScope, _setSpanForScope } from '../utils/spanOnScope';
1112
import {
12-
_getSpanForScope,
13-
_setSpanForScope,
1413
addChildSpanToSpan,
1514
getActiveSpan,
1615
spanIsSampled,
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import type { Scope, Span } from '@sentry/types';
2+
import { addNonEnumerableProperty } from '@sentry/utils';
3+
4+
const SCOPE_SPAN_FIELD = '_sentrySpan';
5+
6+
type ScopeWithMaybeSpan = Scope & {
7+
[SCOPE_SPAN_FIELD]?: Span;
8+
};
9+
10+
/**
11+
* Set the active span for a given scope.
12+
* NOTE: This should NOT be used directly, but is only used internally by the trace methods.
13+
*/
14+
export function _setSpanForScope(scope: Scope, span: Span | undefined): void {
15+
if (span) {
16+
addNonEnumerableProperty(scope as ScopeWithMaybeSpan, SCOPE_SPAN_FIELD, span);
17+
} else {
18+
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
19+
delete (scope as ScopeWithMaybeSpan)[SCOPE_SPAN_FIELD];
20+
}
21+
}
22+
23+
/**
24+
* Get the active span for a given scope.
25+
* NOTE: This should NOT be used directly, but is only used internally by the trace methods.
26+
*/
27+
export function _getSpanForScope(scope: ScopeWithMaybeSpan): Span | undefined {
28+
return scope[SCOPE_SPAN_FIELD];
29+
}

packages/core/src/utils/spanUtils.ts

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type {
22
MeasurementUnit,
33
Primitive,
4-
Scope,
54
Span,
65
SpanAttributes,
76
SpanJSON,
@@ -24,6 +23,7 @@ import type { MetricType } from '../metrics/types';
2423
import { SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '../semanticAttributes';
2524
import type { SentrySpan } from '../tracing/sentrySpan';
2625
import { SPAN_STATUS_OK, SPAN_STATUS_UNSET } from '../tracing/spanstatus';
26+
import { _getSpanForScope } from './spanOnScope';
2727

2828
// These are aligned with OpenTelemetry trace flags
2929
export const TRACE_FLAG_NONE = 0x0;
@@ -244,33 +244,6 @@ export function getRootSpan(span: SpanWithPotentialChildren): Span {
244244
return span[ROOT_SPAN_FIELD] || span;
245245
}
246246

247-
const SCOPE_SPAN_FIELD = '_sentrySpan';
248-
249-
type ScopeWithMaybeSpan = Scope & {
250-
[SCOPE_SPAN_FIELD]?: Span;
251-
};
252-
253-
/**
254-
* Set the active span for a given scope.
255-
* NOTE: This should NOT be used directly, but is only used internally by the trace methods.
256-
*/
257-
export function _setSpanForScope(scope: Scope, span: Span | undefined): void {
258-
if (span) {
259-
addNonEnumerableProperty(scope as ScopeWithMaybeSpan, SCOPE_SPAN_FIELD, span);
260-
} else {
261-
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
262-
delete (scope as ScopeWithMaybeSpan)[SCOPE_SPAN_FIELD];
263-
}
264-
}
265-
266-
/**
267-
* Get the active span for a given scope.
268-
* NOTE: This should NOT be used directly, but is only used internally by the trace methods.
269-
*/
270-
export function _getSpanForScope(scope: ScopeWithMaybeSpan): Span | undefined {
271-
return scope[SCOPE_SPAN_FIELD];
272-
}
273-
274247
/**
275248
* Returns the currently active span.
276249
*/

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ import {
2323
withActiveSpan,
2424
} from '../../../src/tracing';
2525
import { SentryNonRecordingSpan } from '../../../src/tracing/sentryNonRecordingSpan';
26-
import { _setSpanForScope, getActiveSpan, getRootSpan, getSpanDescendants } from '../../../src/utils/spanUtils';
26+
import { _setSpanForScope } from '../../../src/utils/spanOnScope';
27+
import { getActiveSpan, getRootSpan, getSpanDescendants } from '../../../src/utils/spanUtils';
2728
import { TestClient, getDefaultTestClientOptions } from '../../mocks/client';
2829

2930
beforeAll(() => {

0 commit comments

Comments
 (0)