LiteLLM
Instrument litellm.completion, embeddings, streaming, and Router calls in Python. One span per call across 100+ providers, with tokens and cost.
Built by
telemetry.dev
Language
Python
Packages
telemetry-dev-litellm
Category
Model providers
Docs
About the LiteLLM integration
telemetry-dev-litellm instruments litellm.completion, litellm.acompletion, litellm.embedding, litellm.aembedding, streaming CustomStreamWrapper responses, and litellm.Router calls. Because LiteLLM normalizes 100+ providers behind one interface, a single instrument_litellm() call gives you tracing across every provider you route through.
Key features
- One call to instrument everything:
instrument_litellm()patches exactly four package attributes, thread-safe and idempotent;uninstrument_litellm()restores them. - Per-call drop-ins: Import
completion,acompletion,embedding, oraembeddingfromtelemetry_dev_litellmwhen you don't want global monkey-patching — each produces exactly one span even when global instrumentation is active. - Router support: Router deployment attempts are traced per attempt;
wrap_router(router)adds an enclosing Router-level span for retries and fallbacks. - Streaming: Streamed responses are traced through LiteLLM's stream wrapper.
- Fail-open: Without an API key, LiteLLM calls run unchanged and telemetry is a no-op.
Get started
import telemetry_dev
from telemetry_dev_litellm import instrument_litellm
telemetry_dev.init() # reads TELEMETRY_DEV_API_KEY
instrument_litellm()
import litellm
litellm.completion(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "Say hi"}],
)
Note the import-order rule: references captured before instrumentation (from litellm import completion) keep pointing at the original function. Instrument at process startup, or use the telemetry_dev_litellm drop-ins instead.