log2trace-ui - v1.0.0-RC1
    Preparing search index...

    Class TraceTree

    Tree structure for organizing raw OTel Spans for visualization. Spans are kept as-is; relationships and metadata are stored in lookup maps.

    Index

    Constructors

    • Construct a tree directly from precomputed lookup maps.

      Most callers should use TraceTree.build instead. The public constructor exists so trees can be assembled in tests or by callers that already have the indexed structure.

      Parameters

      • roots: Span[]

        Spans with no resolvable parent, sorted by start time.

      • childrenOf: Map<string, Span[]>

        parentSpanId → ordered list of child spans.

      • serviceNameOf: Map<string, string>

        spanId → owning service name.

      Returns TraceTree

    Properties

    childrenOf: Map<string, Span[]>

    parentSpanId → ordered list of child spans.

    roots: Span[]

    Spans with no resolvable parent, sorted by start time.

    serviceNameOf: Map<string, string>

    spanId → owning service name.

    Methods

    • Walk the tree depth-first and return one FlatSpan per span.

      Order matches the visual top-to-bottom order of the waterfall: each root is visited followed by all of its descendants (also depth-first) before moving on to the next root.

      Returns FlatSpan[]

      The complete list of spans annotated with depth and service name.

    • Compute the bounding time range across every span in the tree.

      Both bounds are returned in milliseconds since the Unix epoch, suitable for Date construction and pixel-offset math. An empty tree returns { min: 0, max: 0 }.

      Returns { max: number; min: number }

      The earliest start and latest end timestamp in the tree.

    • Index a flat TraceData payload into a parent-child tree.

      Spans whose parentSpanId does not resolve to a known span in the payload are treated as roots, so dangling references do not silently disappear. Children at every level are sorted by startTimeUnixNano to keep timeline ordering stable.

      Parameters

      • traceData: TraceData

        OTel-shaped trace data, typically produced by transformLogs (from transform.ts) or fetched from a backend.

      Returns TraceTree

      A new TraceTree. Safe to call repeatedly on the same input.

      const tree = TraceTree.build(traceData);
      for (const { span, level } of tree.flatten()) {
      console.log(' '.repeat(level) + span.name);
      }