Skip to main content

TraceLM

TraceLM is a lightweight execution tracer and profiler for LLM pipelines, RAG systems, and FastAPI-based AI services.

It focuses on the tracing primitives that matter when you want to understand execution flow clearly: span trees, traceparent propagation, sampling, profiling, and local inspection.

Why TraceLM

TraceLM exists for developers who want observability without pulling in a full telemetry stack on day one.

  • Trace multi-step LLM workflows with explicit spans
  • Validate trace structure before profiling
  • Continue traces across service boundaries with W3C traceparent
  • Inspect latency, critical path, token usage, and cost from the CLI
  • Export traces to Chrome Trace or OpenTelemetry-compatible JSON

It is intentionally small, local-first, and easy to read.

Installation

pip install tracelm

Try it immediately:

tracelm demo
tracelm init

Optional integrations:

pip install "tracelm[fastapi]"
pip install "tracelm[requests]"
pip install "tracelm[otel]"

Quick Start

TraceLM terminal demo

The fastest path is the built-in demo:

tracelm demo
tracelm latest
tracelm export latest --format chrome

That gives you a real trace, a readable summary, and an exportable file without writing any code.

If you want a starter file generated for you:

tracelm init
tracelm run tracelm_example.py
tracelm latest

tracelm run now executes normal if __name__ == "__main__": scripts correctly, so generated starter files and standard Python entrypoints behave the way users expect.

If you want to trace your own script, create a small instrumented file:

from tracelm.decorator import node

Then run it:

tracelm run test_app.py
tracelm latest

Typical output:

Trace Summary
-------------
Trace ID: 55df12035a754aa080875618bc5794c3
Total Latency: 0.204
Total Spans: 3
Slowest Span: step2
Critical Path: __root__ -> step2
Tokens In: 0
Tokens Out: 0
Total Cost: 0
Anomalies: {'latency_spikes': ['step2']}

Duration Histogram (ms)
-----------------------
0.000-0.100: 1
0.100-0.500: 1
...

Execution Tree
--------------
__root__ (0.204 ms)
+-- step1 (0.082 ms)
\-- step2 (0.101 ms)

Features

  • Hierarchical span tracing with a synthetic root span model
  • W3C traceparent parsing and continuation
  • FastAPI middleware integration
  • Requests-based outbound propagation
  • Head-based probabilistic sampling
  • Critical path and slowest-span analysis
  • Duration histogram generation
  • Token and cost aggregation
  • Trace comparison from the CLI
  • Chrome Trace export
  • OpenTelemetry JSON export and SDK bridge
  • SQLite-backed local trace storage

FastAPI Integration

from fastapi import FastAPI
from tracelm.integrations.fastapi import TraceLMMiddleware

app = FastAPI()
app.add_middleware(TraceLMMiddleware, sample_rate=1.0)


@app.get("/")
def compute():
    return {"status": "ok"}

Import the requests integration to propagate trace context on outbound HTTP calls:

import tracelm.integrations.requests

CLI Commands

Run a Python file under tracing:

tracelm run test_app.py

Apply head sampling:

tracelm run test_app.py --sample-rate 0.1

Generate a starter example file:

tracelm init
tracelm init my_flow.py

Analyze a stored trace:

tracelm analyze <trace_id>

Analyze the most recent trace:

tracelm latest

List stored traces:

tracelm list

Compare two traces:

tracelm compare <trace_id_1> <trace_id_2>

Export to Chrome Trace:

tracelm export <trace_id> --format chrome

You can also use latest anywhere a trace ID is expected:

tracelm export latest --format chrome

Export to OTEL JSON:

tracelm export <trace_id> --format otel

Design Notes

TraceLM keeps a strict execution model:

  • One local root span for CLI-created traces
  • Or one continuation entry span when joining an external trace
  • DAG validation before profiling
  • Async-safe context propagation with ContextVar

This keeps behavior predictable and makes failures explicit.

Scope

TraceLM is currently:

  • Single-process
  • Developer-focused
  • Local-first
  • CLI-centered

It is useful for understanding and instrumenting pipelines before adopting heavier observability infrastructure.

Documentation

  • Architecture: docs/ARCHITECTURE.md
  • Contribution guide: CONTRIBUTING.md

License

MIT

Metadata

Release files for tracelm 0.4.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tracelm 0.4.4
File Size Uploaded Provenance Actions
tracelm-0.4.4.tar.gz 19.5 kB With provenance Details for tracelm-0.4.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for tracelm 0.4.4
File Interpreter ABI Platform Actions
tracelm-0.4.4-py3-none-any.whl Python 3 none any Details for tracelm-0.4.4-py3-none-any.whl

Total release size: 39.5 kB

Release files / tracelm-0.4.4.tar.gz

Download URL tracelm-0.4.4.tar.gz
Size 19.5 kB
Tags Source
SHA-256 checksum
How to use checksums
409b40de1a8f73da2cefa065bbb0f3bdd4a5873de99efab18a89b0993ad24e4f
BLAKE2b-256 checksum
How to use checksums
61acd6e9c250f68a28c01e87162c23d968930b4379550fdaf385229bc82b0e32
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 1, 2026.

Transparency log

Release files / tracelm-0.4.4-py3-none-any.whl

Download URL tracelm-0.4.4-py3-none-any.whl
Size 20.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d77cc28259978a333f144dc59f85fb3b832aa5873285aa3c80b882e6835e38a0
BLAKE2b-256 checksum
How to use checksums
7bba7256b5bba21ce521066c2e7e47039470b1f87656b49250e3a8d86591e75e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 1, 2026.

Transparency log

Security for tracelm 0.4.4

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for tracelm-0.4.4.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 1, 2026.

Transparency log

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page