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
python3 extract_trace_tree.py <trace_file.json>
Examples:
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
./batch_extract_trees.sh
Output
The script writes execution_path.md next to the input trace file. The Markdown contains:
# Trace Execution Pathheader 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:
REASONINGis the reasoning-token count (0 for non-reasoning models)OUTPUTiscompletionTokens - 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 Usageare filtered.
Requirements
- Python 3
- Standard library only (no third-party dependencies)