Skip to main content

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.name
  • lemma.run_id
  • lemma.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.run span 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

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

uselemma_tracing-2.11.0.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

uselemma_tracing-2.11.0-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

Details for the file uselemma_tracing-2.11.0.tar.gz.

File metadata

  • Download URL: uselemma_tracing-2.11.0.tar.gz
  • Upload date:
  • Size: 8.0 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

Hashes for uselemma_tracing-2.11.0.tar.gz
Algorithm Hash digest
SHA256 a33bcfe35f4782014fc345375cd630d73fbbc15ce6afc1c7843adfa3f2f62b1a
MD5 c2309a028d8a1db53b7f2b147356e46f
BLAKE2b-256 f88376104f2ad2e6e8f028036a4695aa6ab02f932689cce3cb62d8212bd1b9b0

See more details on using hashes here.

File details

Details for the file uselemma_tracing-2.11.0-py3-none-any.whl.

File metadata

  • Download URL: uselemma_tracing-2.11.0-py3-none-any.whl
  • Upload date:
  • Size: 11.8 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

Hashes for uselemma_tracing-2.11.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3fb1dc35c5fc5de2eb6e88c76ea047280cde2419779e2dccd49fff07b6fd0d37
MD5 8667522c4383f0616ba9b89c57e55c99
BLAKE2b-256 5c6e265c8fd9b961d8fcbef47f1218e0c12819913761d4c13ee211381c26521c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page