LiteLLM Instrumentation

Installation

$pip install respan-instrumentation-litellm

Classes

LiteLLMInstrumentor

Respan instrumentation plugin that registers a LiteLLM CustomLogger callback and emits canonical chat spans through respan-tracing.

1from respan_instrumentation_litellm import LiteLLMInstrumentor
ParameterTypeDefaultDescription
include_contentboolTrueCapture request messages and assistant response content on chat spans.

Methods

MethodDescription
activate()Register the Respan callback in litellm.callbacks.
deactivate()Remove the callback registered by this instrumentor.

RespanLiteLLMCallback

Low-level callback class used by LiteLLMInstrumentor. Most applications should initialize it through Respan(instrumentations=[LiteLLMInstrumentor()]).

Usage

1import litellm
2from respan import Respan
3from respan_instrumentation_litellm import LiteLLMInstrumentor
4
5respan = Respan(
6 api_key="your-api-key",
7 app_name="litellm-service",
8 instrumentations=[LiteLLMInstrumentor()],
9)
10
11response = litellm.completion(
12 model="gpt-4o-mini",
13 messages=[{"role": "user", "content": "Tell me a joke"}],
14)
15print(response.choices[0].message.content)
16respan.flush()

Async usage

1import litellm
2from respan import Respan
3from respan_instrumentation_litellm import LiteLLMInstrumentor
4
5respan = Respan(instrumentations=[LiteLLMInstrumentor()])
6
7response = await litellm.acompletion(
8 model="gpt-4o-mini",
9 messages=[{"role": "user", "content": "Tell me a joke"}],
10)
11respan.flush()