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
  • ai.agent.input
  • lemma.is_experiment
from uselemma_tracing import TraceContext, wrap_agent

def my_agent(ctx: TraceContext, user_message: str):
    result = do_work(user_message)
    ctx.record_generation_results({"response": result})
    return result

wrapped = wrap_agent("my-agent", my_agent, initial_state={"user_message": user_message})
result, run_id, span = wrapped()

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.4.0.tar.gz (6.8 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.4.0-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: uselemma_tracing-2.4.0.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","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.4.0.tar.gz
Algorithm Hash digest
SHA256 b3a0e62e766e3b2acb7f6e4d5dc7f20484347c53174c0d630631acfd7360d849
MD5 99aa096e5e034e5fa099c4e3ec0fd55d
BLAKE2b-256 ef8f5d058439b4b5a86b57e65a75b6db5d2851d2717111c2aa1f1473e050e40b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: uselemma_tracing-2.4.0-py3-none-any.whl
  • Upload date:
  • Size: 10.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","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.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 094392227cd9c21d7b3f7cedf4bca6e2a32b7b41d89fbd295ae5243535d3f275
MD5 4de90b038a575ece5a3eaec554ba335c
BLAKE2b-256 510d23a660b7389b940e1750468242bf49fb5ed794d52b7855a43a9b254814b4

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