(span: SpanWithPotentialChildren)
| 395 | * Returns an array of the given span and all of its descendants. |
| 396 | */ |
| 397 | export 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. |
no test coverage detected