@sentry/core
Version:
Base implementation for all Sentry JavaScript SDKs
39 lines (38 loc) • 1.87 kB
JavaScript
import { addNonEnumerableProperty } from "../utils/object.js";
import { derefWeakRef, makeWeakRef } from "../utils/weakRef.js";
// src/tracing/utils.ts
const SCOPE_ON_START_SPAN_FIELD = "_sentryScope";
const ISOLATION_SCOPE_ON_START_SPAN_FIELD = "_sentryIsolationScope";
const TRACER_PROVIDER_SPAN_FIELD = Symbol.for("sentry.tracerProviderSpan");
/** Store the scope & isolation scope for a span, which can the be used when it is finished. */
function setCapturedScopesOnSpan(span, scope, isolationScope) {
if (span) {
addNonEnumerableProperty(span, ISOLATION_SCOPE_ON_START_SPAN_FIELD, makeWeakRef(isolationScope));
addNonEnumerableProperty(span, SCOPE_ON_START_SPAN_FIELD, scope);
}
}
/**
* Grabs the scope and isolation scope off a span that were active when the span was started.
* If WeakRef was used and scopes have been garbage collected, returns undefined for those scopes.
*/
function getCapturedScopesOnSpan(span) {
const spanWithScopes = span;
return {
scope: spanWithScopes[SCOPE_ON_START_SPAN_FIELD],
isolationScope: derefWeakRef(spanWithScopes[ISOLATION_SCOPE_ON_START_SPAN_FIELD])
};
}
/**
* Mark a span as created by the `SentryTracerProvider` (via the OTel tracer). Set by `SentryTracer`
* on every span it creates; read by `SentrySpan.end()` to seal the span against further writes once
* it has ended, mirroring OTel SDK spans (which are immutable after `end()`).
*/
function markSpanAsTracerProviderSpan(span) {
addNonEnumerableProperty(span, TRACER_PROVIDER_SPAN_FIELD, true);
}
/** Whether a span was created by the `SentryTracerProvider` (see {@link markSpanAsTracerProviderSpan}). */
function spanIsTracerProviderSpan(span) {
return span[TRACER_PROVIDER_SPAN_FIELD] === true;
}
export { getCapturedScopesOnSpan, markSpanAsTracerProviderSpan, setCapturedScopesOnSpan, spanIsTracerProviderSpan };
//# sourceMappingURL=utils.js.map