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

Function spanToStreamedSpanJSON

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

Source from the content-addressed store, hash-verified

212 * Convert a span to the intermediate {@link StreamedSpanJSON} representation.
213 */
214export function spanToStreamedSpanJSON(span: Span): StreamedSpanJSON {
215 if (spanIsSentrySpan(span)) {
216 return span.getStreamedSpanJSON();
217 }
218
219 const { spanId: span_id, traceId: trace_id } = span.spanContext();
220
221 // Handle a span from @opentelemetry/sdk-base-trace's `Span` class
222 if (spanIsOpenTelemetrySdkTraceBaseSpan(span)) {
223 const { attributes, startTime, name, endTime, status, links } = span;
224
225 return {
226 name,
227 span_id,
228 trace_id,
229 parent_span_id: getOtelParentSpanId(span),
230 start_timestamp: spanTimeInputToSeconds(startTime),
231 end_timestamp: spanTimeInputToSeconds(endTime),
232 is_segment: span === INTERNAL_getSegmentSpan(span),
233 status: getSimpleStatus(status),
234 attributes: addStatusMessageAttribute(attributes, status),
235 links: getStreamedSpanLinks(links),
236 };
237 }
238
239 // Finally, as a fallback, at least we have `spanContext()`....
240 // This should not actually happen in reality, but we need to handle it for type safety.
241 return {
242 span_id,
243 trace_id,
244 start_timestamp: 0,
245 name: '',
246 end_timestamp: 0,
247 status: 'ok',
248 is_segment: span === INTERNAL_getSegmentSpan(span),
249 };
250}
251
252/**
253 * In preparation for the next major of OpenTelemetry, we want to support

Callers 4

spanUtils.test.tsFile · 0.90
captureSpanFunction · 0.90
_emitWebVitalSpanFunction · 0.90
_sendInpSpanFunction · 0.90

Calls 10

spanIsSentrySpanFunction · 0.85
getOtelParentSpanIdFunction · 0.85
spanTimeInputToSecondsFunction · 0.85
INTERNAL_getSegmentSpanFunction · 0.85
getSimpleStatusFunction · 0.85
getStreamedSpanLinksFunction · 0.85
getStreamedSpanJSONMethod · 0.80
spanContextMethod · 0.65

Tested by

no test coverage detected