File size: 2,037 Bytes
8c10cf2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | # Extract Trace Tree
Langfuse Trace tree extraction and analysis tool
## Overview
This tool extracts an execution-path tree from a Langfuse trace JSON file (typically `langfuse_trace.json`).
It builds a parent/child tree, sorts siblings by timestamp, applies noise filtering (A2A + HTTP), and outputs
both a console view and a Markdown report.
## Quick Start
### Single file
```bash
python3 extract_trace_tree.py <trace_file.json>
```
Examples:
```bash
python3 extract_trace_tree.py GPT-5/BookWriter-MCP/test_results/run_20251104_045654/langfuse_trace.json
python3 extract_trace_tree.py GPT-5/BookWriter-A2A/test_results/run_20251103_195358/langfuse_trace.json
python3 extract_trace_tree.py GPT-5/BookWriter-H_A2A/test_results/run_20251104_010743/langfuse_trace.json
```
### Batch
```bash
./batch_extract_trees.sh
```
## Output
The script writes `execution_path.md` next to the input trace file. The Markdown contains:
- `# Trace Execution Path` header with metadata
- `## Execution Path Tree` (tree in a fenced code block)
- `## Statistics`
- `### Error Summary` (only when errors exist)
### Token format
LLM nodes show:
```
(prompt→completion [REASONING:X, OUTPUT:Y], total: Z)
```
Where:
- `REASONING` is the reasoning-token count (0 for non-reasoning models)
- `OUTPUT` is `completionTokens - reasoningTokens`
### Batch label (write_a_book_with_flows)
For write-book scenarios the tree may include:
- `BATCH1` / `BATCH2`
- `[BUSINESS-RETRY]` when the same chapter is retried
### Truncated errors
Long errors are truncated and marked with `[TRUNCATED]`.
## Project Type Detection
Project type is detected from the trace path:
- `*-MCP/` -> MCP
- `*-A2A/` -> A2A
- `*-A2A_mix/` -> A2A_mix
- `*-H_A2A/` -> A2A
## Filtering
- HTTP client tracing nodes (OpenTelemetry httpx) are filtered.
- A2A framework internals are filtered for A2A/A2A_mix.
- Tool telemetry spans such as `Tool Usage`/`Tool Repeated Usage` are filtered.
## Requirements
- Python 3
- Standard library only (no third-party dependencies)
|