Skip to content

Commit d8adefd

Browse files
authored
Revert "ref(core): Wrap isolationscope in WeakRef when storing it on spans …"
This reverts commit b685be6.
1 parent d024907 commit d8adefd

File tree

2 files changed

+4
-290
lines changed

2 files changed

+4
-290
lines changed

packages/core/src/tracing/utils.ts

Lines changed: 4 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,29 @@
11
import type { Scope } from '../scope';
22
import type { Span } from '../types-hoist/span';
33
import { addNonEnumerableProperty } from '../utils/object';
4-
import { GLOBAL_OBJ } from '../utils/worldwide';
54

65
const SCOPE_ON_START_SPAN_FIELD = '_sentryScope';
76
const ISOLATION_SCOPE_ON_START_SPAN_FIELD = '_sentryIsolationScope';
87

9-
type ScopeWeakRef = { deref(): Scope | undefined } | Scope;
10-
118
type SpanWithScopes = Span & {
129
[SCOPE_ON_START_SPAN_FIELD]?: Scope;
13-
[ISOLATION_SCOPE_ON_START_SPAN_FIELD]?: ScopeWeakRef;
10+
[ISOLATION_SCOPE_ON_START_SPAN_FIELD]?: Scope;
1411
};
1512

16-
/** Wrap a scope with a WeakRef if available, falling back to a direct scope. */
17-
function wrapScopeWithWeakRef(scope: Scope): ScopeWeakRef {
18-
try {
19-
// @ts-expect-error - WeakRef is not available in all environments
20-
const WeakRefClass = GLOBAL_OBJ.WeakRef;
21-
if (typeof WeakRefClass === 'function') {
22-
return new WeakRefClass(scope);
23-
}
24-
} catch {
25-
// WeakRef not available or failed to create
26-
// We'll fall back to a direct scope
27-
}
28-
29-
return scope;
30-
}
31-
32-
/** Try to unwrap a scope from a potential WeakRef wrapper. */
33-
function unwrapScopeFromWeakRef(scopeRef: ScopeWeakRef | undefined): Scope | undefined {
34-
if (!scopeRef) {
35-
return undefined;
36-
}
37-
38-
if (typeof scopeRef === 'object' && 'deref' in scopeRef && typeof scopeRef.deref === 'function') {
39-
try {
40-
return scopeRef.deref();
41-
} catch {
42-
return undefined;
43-
}
44-
}
45-
46-
// Fallback to a direct scope
47-
return scopeRef as Scope;
48-
}
49-
5013
/** Store the scope & isolation scope for a span, which can the be used when it is finished. */
5114
export function setCapturedScopesOnSpan(span: Span | undefined, scope: Scope, isolationScope: Scope): void {
5215
if (span) {
53-
addNonEnumerableProperty(span, ISOLATION_SCOPE_ON_START_SPAN_FIELD, wrapScopeWithWeakRef(isolationScope));
54-
// We don't wrap the scope with a WeakRef here because webkit aggressively garbage collects
55-
// and scopes are not held in memory for long periods of time.
16+
addNonEnumerableProperty(span, ISOLATION_SCOPE_ON_START_SPAN_FIELD, isolationScope);
5617
addNonEnumerableProperty(span, SCOPE_ON_START_SPAN_FIELD, scope);
5718
}
5819
}
5920

6021
/**
6122
* Grabs the scope and isolation scope off a span that were active when the span was started.
62-
* If WeakRef was used and scopes have been garbage collected, returns undefined for those scopes.
6323
*/
6424
export function getCapturedScopesOnSpan(span: Span): { scope?: Scope; isolationScope?: Scope } {
65-
const spanWithScopes = span as SpanWithScopes;
66-
6725
return {
68-
scope: spanWithScopes[SCOPE_ON_START_SPAN_FIELD],
69-
isolationScope: unwrapScopeFromWeakRef(spanWithScopes[ISOLATION_SCOPE_ON_START_SPAN_FIELD]),
26+
scope: (span as SpanWithScopes)[SCOPE_ON_START_SPAN_FIELD],
27+
isolationScope: (span as SpanWithScopes)[ISOLATION_SCOPE_ON_START_SPAN_FIELD],
7028
};
7129
}

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

Lines changed: 0 additions & 244 deletions
This file was deleted.

0 commit comments

Comments
 (0)