TraceLite

Distributed tracing from scratch. Zero dependencies. 193 tests. Python only.

Set up a tracer. Three lines, no config files.

app.py
from tracelite.tracer import TracerProvider
from tracelite.span import Resource, SpanKind
from tracelite.processor import SimpleSpanProcessor
from tracelite.exporter import ConsoleExporter

provider = TracerProvider(
    resource=Resource(attributes={"service.name": "my-api"})
)
provider.add_processor(SimpleSpanProcessor(ConsoleExporter()))
tracer = provider.get_tracer()

with tracer.start_span("GET /users", kind=SpanKind.SERVER) as span:
    span.set_attribute("http.method", "GET")

    with tracer.start_span("fetch_from_db") as db:
        db.set_attribute("db.system", "postgresql")
        # ...your query runs here...

    span.set_attribute("http.status_code", 200)

See the trace. Waterfall view renders in the terminal or the built-in dashboard.

trace output
gateway › GET /api/users
245ms
gateway › auth_middleware
18ms
gateway › rate_limiter
6ms
user-svc › GET /internal/users
198ms
user-svc › check_cache
9ms
database › SELECT users
172ms
gateway › serialize
12ms

Propagate context across services. W3C Trace Context headers link spans into a single trace.

propagation.py
from tracelite.propagator import W3CTraceContextPropagator
from tracelite.context import SpanContext

propagator = W3CTraceContextPropagator()

# Service A: inject into outgoing request
with tracer.start_span("call-service-b", kind=SpanKind.CLIENT) as span:
    headers = {}
    ctx = SpanContext(span.trace_id, span.span_id, trace_flags=1)
    propagator.inject(ctx, headers)
    # → {"traceparent": "00-4bf92f...-00f067...-01"}

# Service B: extract from incoming request
parent = propagator.extract(incoming_headers)
with tracer.start_span("handle-request", parent=parent) as span:
    # Same trace_id, linked as child span
    pass

Map your services. Auto-generated dependency graph with edge metrics.

service map
gateway 142 spans
──→
user-api 89 spans · 2% err
──→
database 89 spans · p99 45ms
0deps
External dependencies
193
Tests passing
18modules
Core components
5.5klines
Python, no filler

What's inside.

W3C Trace Context
traceparent / tracestate header propagation across service boundaries
5 Sampling Strategies
AlwaysOn, AlwaysOff, Probabilistic, RateLimiting, ParentBased
SQLite Storage
WAL-mode persistence with indexed queries, retention, and compaction
RED Metrics
Rate, Errors, Duration with p50/p90/p95/p99 percentiles
Critical Path Analysis
Find the span chain determining end-to-end latency
@trace Decorator
Zero-boilerplate instrumentation with argument recording
WSGI Middleware
Drop-in request tracing for any WSGI application
HTML Dashboard
Self-contained dashboard with trace list, waterfall, and service map
View on GitHub → Read the docs