(spans: Sequence[dict[str, Any]])
| 813 | |
| 814 | |
| 815 | def build_tree(spans: Sequence[dict[str, Any]]) -> tuple[dict[str, Any], str | None]: |
| 816 | span_tree: dict[str, tuple[dict[str, Any], list[dict[str, Any]]]] = {} |
| 817 | segment_id = None |
| 818 | |
| 819 | for span in spans: |
| 820 | span_id = span["span_id"] |
| 821 | is_root = span.get("is_segment", False) |
| 822 | if is_root: |
| 823 | segment_id = span_id |
| 824 | if span_id not in span_tree: |
| 825 | span_tree[span_id] = (span, []) |
| 826 | |
| 827 | for span, _ in span_tree.values(): |
| 828 | parent_id = span.get("parent_span_id") |
| 829 | if parent_id is not None and parent_id in span_tree: |
| 830 | _, children = span_tree[parent_id] |
| 831 | children.append(span) |
| 832 | |
| 833 | return span_tree, segment_id |
| 834 | |
| 835 | |
| 836 | def dfs( |
no test coverage detected