OpenTelemetry-based tracing module for Lemma
Project description
uselemma-tracing
OpenTelemetry-based tracing for AI agents. Capture inputs, outputs, timing, token usage, and errors — then view everything in Lemma.
Installation
pip install uselemma-tracing
Quick Start
1. Register the tracer provider
Call register_otel once when your application starts. It reads LEMMA_API_KEY and LEMMA_PROJECT_ID from environment variables by default.
from uselemma_tracing import register_otel
register_otel()
You can also enable experiment mode globally for the process:
from uselemma_tracing import enable_experiment_mode
enable_experiment_mode()
2. Wrap your agent
wrap_agent creates a root OpenTelemetry span named ai.agent.run and records:
ai.agent.namelemma.run_idlemma.is_experiment
from uselemma_tracing import TraceContext, wrap_agent
def my_agent(ctx: TraceContext, user_message: str):
result = do_work(user_message)
ctx.on_complete(result)
return result
wrapped = wrap_agent("my-agent", my_agent, auto_end_root=True)
result, run_id, span = wrapped("hello")
Export Behavior
- Spans are exported in run-specific batches keyed by
lemma.run_id. - A run batch is exported when its top-level
ai.agent.runspan ends. force_flush()exports remaining runs in separate batches per run.- Spans with
instrumentation_scope.name == "next.js"are excluded from export.
Environment Variables
| Variable | Description |
|---|---|
LEMMA_API_KEY |
Your Lemma API key |
LEMMA_PROJECT_ID |
Your Lemma project ID |
Both are required unless passed explicitly to register_otel().
Documentation
- Tracing Overview — concepts, API reference, and usage patterns
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file uselemma_tracing-2.12.0.tar.gz.
File metadata
- Download URL: uselemma_tracing-2.12.0.tar.gz
- Upload date:
- Size: 8.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ef2b5410f5d2207c255478f3116206371a5fc9ca691e1927b1b0675b8cd6f7be
|
|
| MD5 |
3d2869ca658b3f5fe8f3b9705a349fba
|
|
| BLAKE2b-256 |
beb7b379bc0b2340a056c7e66ab3cf4bcaad4a0a7f6d94e5f8398f26baecbac1
|
File details
Details for the file uselemma_tracing-2.12.0-py3-none-any.whl.
File metadata
- Download URL: uselemma_tracing-2.12.0-py3-none-any.whl
- Upload date:
- Size: 12.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0512967279d3f264f4d6f0df32c42ae42a34f3f5a516e6d8424e2c201eac2f52
|
|
| MD5 |
3d3c84110d550735e6d0c90127781e18
|
|
| BLAKE2b-256 |
b53f23f83441ece356a60a9b924126ecd769741e6f4fcbb38c756e81be87ec37
|