Command Palette

Search for a command to run...

Hectal
Phase 11: Observability and Operations
LLM Engineering · Exercise 3 of 5 PreviousNext
Intermediate

Print a trace tree with self time

Spans are tuples (id, parent, name, start_ms, end_ms) in start order; a parent of 0 means the root. Write span_tree(spans) that returns a list of lines, one per span, indented two spaces per level of depth.

Each line is <name> total=<ms> self=<ms>, where self is total minus the total of the span's direct children.

What Check tests

  1. A single root span
  2. Children are indented and reduce the parent's self time
  3. Grandchildren are indented twice
  4. Only direct children are subtracted

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

main.py
Sign in to run your code.

Output

Press Run to see what your program prints.