Skip to content

Commit a416137

Browse files
committed
revert packages/core/src/tracing/utils.ts and amend dsc logic
1 parent f31c438 commit a416137

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

dev-packages/rollup-utils/plugins/bundlePlugins.mjs

+3
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ export function makeTerserPlugin() {
126126
'_sentryId',
127127
// Keeps the frozen DSC on a Sentry Span
128128
'_frozenDsc',
129+
// These are used to keep span & scope relationships
130+
'_sentryScope',
131+
'_sentryIsolationScope',
129132
// require-in-the-middle calls `Module._resolveFilename`. We cannot mangle this (AWS lambda layer bundle).
130133
'_resolveFilename',
131134
// Set on e.g. the shim feedbackIntegration to be able to detect it

packages/core/src/tracing/dynamicSamplingContext.ts

+4-13
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,18 @@ import {
88
baggageHeaderToDynamicSamplingContext,
99
dynamicSamplingContextToSentryBaggageHeader,
1010
} from '../utils-hoist/baggage';
11-
import { addNonEnumerableProperty, dropUndefinedKeys } from '../utils-hoist/object';
11+
import { dropUndefinedKeys } from '../utils-hoist/object';
1212
import { hasSpansEnabled } from '../utils/hasSpansEnabled';
1313
import { getRootSpan, spanIsSampled, spanToJSON } from '../utils/spanUtils';
1414
import { getCapturedScopesOnSpan } from './utils';
1515

16-
/**
17-
* If you change this value, also update the terser plugin config to
18-
* avoid minification of the object property!
19-
*/
20-
const FROZEN_DSC_FIELD = '_frozenDsc';
21-
22-
type SpanWithMaybeDsc = Span & {
23-
[FROZEN_DSC_FIELD]?: Partial<DynamicSamplingContext> | undefined;
24-
};
16+
const SPAN_TO_DSC_MAP = new WeakMap<Span, Partial<DynamicSamplingContext>>();
2517

2618
/**
2719
* Freeze the given DSC on the given span.
2820
*/
2921
export function freezeDscOnSpan(span: Span, dsc: Partial<DynamicSamplingContext>): void {
30-
const spanWithMaybeDsc = span as SpanWithMaybeDsc;
31-
addNonEnumerableProperty(spanWithMaybeDsc, FROZEN_DSC_FIELD, dsc);
22+
SPAN_TO_DSC_MAP.set(span, dsc);
3223
}
3324

3425
/**
@@ -91,7 +82,7 @@ export function getDynamicSamplingContextFromSpan(span: Span): Readonly<Partial<
9182
}
9283

9384
// For core implementation, we freeze the DSC onto the span as a non-enumerable property
94-
const frozenDsc = (rootSpan as SpanWithMaybeDsc)[FROZEN_DSC_FIELD];
85+
const frozenDsc = SPAN_TO_DSC_MAP.get(rootSpan);
9586
if (frozenDsc) {
9687
return applyLocalSampleRateToDsc(frozenDsc);
9788
}

packages/core/src/tracing/utils.ts

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
import type { Scope } from '../scope';
22
import type { Span } from '../types-hoist';
3+
import { addNonEnumerableProperty } from '../utils-hoist/object';
34

4-
const SPAN_TO_SCOPE_MAP = new WeakMap<Span, Scope>();
5-
const SPAN_TO_ISOLATION_SCOPE_MAP = new WeakMap<Span, Scope>();
5+
const SCOPE_ON_START_SPAN_FIELD = '_sentryScope';
6+
const ISOLATION_SCOPE_ON_START_SPAN_FIELD = '_sentryIsolationScope';
7+
8+
type SpanWithScopes = Span & {
9+
[SCOPE_ON_START_SPAN_FIELD]?: Scope;
10+
[ISOLATION_SCOPE_ON_START_SPAN_FIELD]?: Scope;
11+
};
612

713
/** Store the scope & isolation scope for a span, which can the be used when it is finished. */
814
export function setCapturedScopesOnSpan(span: Span | undefined, scope: Scope, isolationScope: Scope): void {
915
if (span) {
10-
SPAN_TO_SCOPE_MAP.set(span, scope);
11-
SPAN_TO_ISOLATION_SCOPE_MAP.set(span, isolationScope);
16+
addNonEnumerableProperty(span, ISOLATION_SCOPE_ON_START_SPAN_FIELD, isolationScope);
17+
addNonEnumerableProperty(span, SCOPE_ON_START_SPAN_FIELD, scope);
1218
}
1319
}
1420

@@ -17,7 +23,7 @@ export function setCapturedScopesOnSpan(span: Span | undefined, scope: Scope, is
1723
*/
1824
export function getCapturedScopesOnSpan(span: Span): { scope?: Scope; isolationScope?: Scope } {
1925
return {
20-
scope: SPAN_TO_SCOPE_MAP.get(span),
21-
isolationScope: SPAN_TO_ISOLATION_SCOPE_MAP.get(span),
26+
scope: (span as SpanWithScopes)[SCOPE_ON_START_SPAN_FIELD],
27+
isolationScope: (span as SpanWithScopes)[ISOLATION_SCOPE_ON_START_SPAN_FIELD],
2228
};
2329
}

0 commit comments

Comments
 (0)