MCPcopy Index your code
hub / github.com/getsentry/sentry-javascript / spanToTraceContext

Function spanToTraceContext

packages/core/src/utils/spanUtils.ts:66–81  ·  view source on GitHub ↗
(span: Span)

Source from the content-addressed store, hash-verified

64 * Convert a span to a trace context, which can be sent as the `trace` context in a non-transaction event.
65 */
66export function spanToTraceContext(span: Span): TraceContext {
67 const { spanId, traceId: trace_id, isRemote } = span.spanContext();
68
69 // If the span is remote, we use a random/virtual span as span_id to the trace context,
70 // and the remote span as parent_span_id
71 const parent_span_id = isRemote ? spanId : spanToJSON(span).parent_span_id;
72 const scope = getCapturedScopesOnSpan(span).scope;
73
74 const span_id = isRemote ? scope?.getPropagationContext().propagationSpanId || generateSpanId() : spanId;
75
76 return {
77 parent_span_id,
78 span_id,
79 trace_id,
80 };
81}
82
83/**
84 * Convert a Span to a Sentry trace header.

Callers 6

captureToolErrorFunction · 0.90
spanUtils.test.tsFile · 0.90
applySpanToEventFunction · 0.90
_getTraceInfoFromScopeFunction · 0.90
getTraceContextForScopeFunction · 0.90
setupEventContextTraceFunction · 0.90

Calls 5

getCapturedScopesOnSpanFunction · 0.90
generateSpanIdFunction · 0.90
spanToJSONFunction · 0.85
getPropagationContextMethod · 0.80
spanContextMethod · 0.65

Tested by

no test coverage detected