import { TraceFlags } from '@opentelemetry/api'; import { debug, SEMANTIC_LINK_ATTRIBUTE_LINK_TYPE, getActiveSpan, spanIsSampled } from '@sentry/core'; import { DEBUG_BUILD } from '../debug-build.js'; const SENTRY_TRACE_LINK_KEY_PREFIX = "__SENTRY_TRACE_LINK__"; function getTraceLinkKey(methodName) { return `${SENTRY_TRACE_LINK_KEY_PREFIX}${methodName}`; } function storeSpanContext(originalStorage, methodName) { try { const activeSpan = getActiveSpan(); if (activeSpan) { const spanContext = activeSpan.spanContext(); const storedContext = { traceId: spanContext.traceId, spanId: spanContext.spanId, sampled: spanIsSampled(activeSpan) }; originalStorage.kv.put(getTraceLinkKey(methodName), storedContext); } } catch (error) { DEBUG_BUILD && debug.log(`[CloudflareClient] Error storing span context for method ${methodName}`, error); } } function getStoredSpanContext(originalStorage, methodName) { try { return originalStorage.kv.get(getTraceLinkKey(methodName)); } catch (error) { DEBUG_BUILD && debug.log(`[CloudflareClient] Error retrieving span context for method ${methodName}`, error); return void 0; } } function buildSpanLinks(storedContext) { return [ { context: { traceId: storedContext.traceId, spanId: storedContext.spanId, traceFlags: storedContext.sampled ? TraceFlags.SAMPLED : TraceFlags.NONE }, attributes: { [SEMANTIC_LINK_ATTRIBUTE_LINK_TYPE]: "previous_trace" } } ]; } export { buildSpanLinks, getStoredSpanContext, getTraceLinkKey, storeSpanContext }; //# sourceMappingURL=traceLinks.js.map