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

Function getSpanDescendants

packages/core/src/utils/spanUtils.ts:397–417  ·  view source on GitHub ↗
(span: SpanWithPotentialChildren)

Source from the content-addressed store, hash-verified

395 * Returns an array of the given span and all of its descendants.
396 */
397export function getSpanDescendants(span: SpanWithPotentialChildren): Span[] {
398 const resultSet = new Set<Span>();
399
400 function addSpanChildren(span: SpanWithPotentialChildren): void {
401 // This exit condition is required to not infinitely loop in case of a circular dependency.
402 if (resultSet.has(span)) {
403 return;
404 // We want to ignore unsampled spans (e.g. non recording spans)
405 } else if (spanIsSampled(span)) {
406 resultSet.add(span);
407 const childSpans = span[CHILD_SPANS_FIELD] ? Array.from(span[CHILD_SPANS_FIELD]) : [];
408 for (const childSpan of childSpans) {
409 addSpanChildren(childSpan);
410 }
411 }
412 }
413
414 addSpanChildren(span);
415
416 return Array.from(resultSet);
417}
418
419/**
420 * Returns the root span of a given span.

Callers 7

trace.test.tsFile · 0.90
applyFunction · 0.90
onIdleSpanEndedFunction · 0.90
startIdleSpanFunction · 0.90
handle.test.tsFile · 0.90

Calls 2

addSpanChildrenFunction · 0.85
fromMethod · 0.45

Tested by

no test coverage detected