A lightweight, self-contained system for viewing structured logs as collapsible execution trees using OpenTelemetry spans and structlog.
- π³ Collapsible Trace Trees - Visualize function call hierarchies with nested spans
- π Structured Logging - JSON logs with automatic trace/span ID injection
- π Source Location Tracking - Automatic file path and line number capture
- π No External Dependencies - No Zipkin, Jaeger, or other backend required
- π Simple Setup - Just SQLite + FastAPI + Static HTML/JS
- π¨ Modern UI - Clean, responsive web interface with advanced features
- π VSCode/Cursor Plugin Ready - Compatible with IDE plugins for in-editor trace viewing
# Install
uv sync
# Start the viewer server
uv run aitrace
# Run example (in another terminal)
uv sync --extra examples
uv run python test/02_simple.py
# View traces at http://localhost:8000For detailed instructions, see the π Quick Start Guide.
from aitrace import setup_tracing, auto_span, BufferedLogger
# Initialize
tracer = setup_tracing("my-service")
buffered = BufferedLogger(target="http://localhost:8000/api/ingest")
log = buffered.logger
# Instrument your code
@auto_span()
def my_function(arg):
log.info("doing_work", arg=arg)
return result
# Auto-send logs to viewer
with buffered.trace_context(tracer, "my_operation"):
my_function("test")
# Logs automatically sent when context exits- π Quick Start Guide - Get up and running in 3 steps
- βοΈ Configuration Guide - Server and environment setup
- ποΈ Trace Viewer Guide - Web-based trace visualization
- π Deployment Guide - Production deployment options
- ποΈ Architecture & Design Decisions - Technical decisions for developers and AI agents
- π οΈ Development Guide - Setup, testing, and contributing
- π Changelog - Version history and breaking changes
- π Trace Record Format - JSON format specification
- π Source Location Tracking - IDE integration details
- π VSCode Plugin Format - Plugin integration guide
βββββββββββββββ
β Your App β Uses @auto_span decorator + structlog
ββββββββ¬βββββββ
β
β JSON logs (trace_id, span_id, parent_span_id)
β
βΌ
βββββββββββββββ
β SQLite β Stores logs indexed by trace/span
ββββββββ¬βββββββ
β
β REST API
β
βΌ
βββββββββββββββ
β Web UI β Browse traces, view collapsible trees
βββββββββββββββ
See AGENTS.md for comprehensive architectural documentation.
mytrace/
βββ aitrace/ # Python tracing library
β βββ buffer.py # BufferedLogger for log ingestion
β βββ server.py # FastAPI server + SQLite backend
β βββ static/ # Web UI (simple viewer)
βββ aitrace_viewer/ # Advanced web viewer (Preact + Vite)
βββ test/ # Example scripts
βββ docs/ # Documentation
β βββ quickstart.md
β βββ configuration.md
β βββ deployment.md
β βββ viewer.md
β βββ development.md
β βββ archive/ # Historical documentation
βββ README.md # This file
βββ AGENTS.md # Architecture & technical decisions
βββ CHANGELOG.md # Version history
# Simple chatbot
uv run python test/02_simple.py
# Router with multiple agents
uv run python test/03_router.py
# BufferedLogger patterns
uv run python test/04_buffered_simple.py
# Output target modes (HTTP, file, stdout)
uv run python test/05_target_modes.pySee test/README.md for detailed example documentation.
Quick configuration examples:
# Custom port
aitrace --port 9000
# Development mode
aitrace --reload --log-level debug
# Custom database
aitrace --db-path /tmp/traces.db
# Using environment variables
export AITRACE_PORT=9000
export AITRACE_LOG_LEVEL=debug
aitraceSee Configuration Guide for complete reference.
- Python 3.10+
- Modern web browser for UI
- Node.js 18+ (optional, for advanced viewer development)
uv syncpip install -e .uv sync --extra examplesDevelopment & Debugging
- Trace LangGraph/LangChain execution flows
- Debug nested function calls
- Inspect LLM prompts and responses
Production Monitoring
- Lightweight tracing without external services
- Local SQLite storage for moderate volumes
- Export logs to files for archival
Testing & CI/CD
- Capture traces as test artifacts
- Generate HTML traces offline
- File-based logging for reproducibility
MIT - See LICENSE for details
Built on OpenTelemetry, structlog, and FastAPI. Inspired by Jaeger and Zipkin, simplified for local development and small-scale production use.
Need Help? Check the Quick Start Guide or AGENTS.md for architecture details.