tracemaid
OpenTelemetry trace analysis and Mermaid diagram generation library.
Overview
tracemaid is a Python library that parses OpenTelemetry traces, extracts meaningful features from spans, selects the most important spans using machine learning clustering algorithms, and generates Mermaid diagrams for visualization.
Features
- Trace Parsing: Parse OpenTelemetry JSON/OTLP trace formats into structured Span and Trace objects
- Feature Extraction: Extract 6-dimensional feature vectors from spans for analysis:
- Duration (normalized to [0,1] range)
- Depth in trace tree (normalized)
- Child count (normalized)
- Error status (binary flag)
- Is root span (binary flag)
- Relative start time
- Intelligent Span Selection: Select important spans using:
- Convex Hull algorithm (boundary spans in feature space)
- K-Means clustering (representative spans from clusters)
- Mermaid Diagram Generation: Generate visual flowchart diagrams:
- Color-coded nodes (error spans in red, slow spans in orange)
- Parent-child edge relationships
- Optional metadata (duration, depth) in labels
Installation
# From PyPI (when published)
pip install tracemaid
# From source
git clone https://github.com/karthyick/tracemaid.git
cd tracemaid
pip install -e .
# With development dependencies
pip install -e ".[dev]"
Quick Start
Python API
from tracemaid import OTelParser, SpanSelector, MermaidGenerator
# Parse a trace file
parser = OTelParser()
with open("trace.json", "r") as f:
trace = parser.parse_json(f.read())
# Select important spans using ConvexHull + K-Means
selector = SpanSelector()
important_spans = selector.select_from_trace(trace, max_spans=10)
# Generate Mermaid diagram
generator = MermaidGenerator()
diagram = generator.generate(important_spans, trace)
print(diagram)
CLI
# Analyze a trace and generate a Mermaid diagram (default)
tracemaid trace.json
# Output to a file with max 15 spans
tracemaid trace.json -o diagram.md -n 15
# Generate JSON output with selected spans
tracemaid trace.json --format json
# Include metadata (duration, depth) in diagram labels
tracemaid trace.json --metadata
# Disable styling (colors for error/slow spans)
tracemaid trace.json --no-style
# Verbose mode
tracemaid trace.json -v
Output Examples
Flowchart Diagram
flowchart TD
span_6e0c63257de34c92["api-gateway: HTTP GET /api/orders"]
span_9h3f96580gh67fc5["order-service: GetOrders"]
el8k41035lm12kh0["database-service: SELECT order_items"]
span_6e0c63257de34c92 --> span_9h3f96580gh67fc5
span_9h3f96580gh67fc5 --> el8k41035lm12kh0
%% Style definitions
classDef errorStyle fill:#ff6b6b,stroke:#c92a2a,stroke-width:2px,color:#fff
class el8k41035lm12kh0 errorStyle
classDef normalStyle fill:#74c0fc,stroke:#1c7ed6,stroke-width:1px,color:#000
class span_6e0c63257de34c92,span_9h3f96580gh67fc5 normalStyle
Requirements
- Python 3.9+
- numpy
- scipy
- scikit-learn
Development
# Install dev dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Run tests with coverage
pytest --cov=tracemaid --cov-report=html
License
MIT License - see LICENSE file for details.
Author
Metadata
Release files for tracemaid 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tracemaid-0.1.3.tar.gz | 78.1 kB | Without provenance | Details for tracemaid-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tracemaid-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for tracemaid-0.1.3-py3-none-any.whl |
Total release size: 115.2 kB
Release files / tracemaid-0.1.3.tar.gz
| Download URL | tracemaid-0.1.3.tar.gz |
|---|---|
| Size | 78.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
38c68eb6e64569b3f60395620448dabba32481a5215bdbb3f727f5cb160337f4
|
|
BLAKE2b-256 checksum How to use checksums |
03ce5e512815e78d2795d58df99cbcda8a4190b4e8911fc7402073e973a68b1a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Release files / tracemaid-0.1.3-py3-none-any.whl
| Download URL | tracemaid-0.1.3-py3-none-any.whl |
|---|---|
| Size | 37.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7f9bb3133bc93f6ad12d7177a77ed7c131b32c2c7cc4b4921eb235c4f0ffa617
|
|
BLAKE2b-256 checksum How to use checksums |
1e79cb3aaa39597f3fa9908fe2be3ffd5b1f797fdd34e08da6a01412930f1ce3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Security for tracemaid 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.