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.

from 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

import litellm
from respan import Respan
from respan_instrumentation_litellm import LiteLLMInstrumentor
respan = Respan(
api_key="your-api-key",
app_name="litellm-service",
instrumentations=[LiteLLMInstrumentor()],
)
response = litellm.completion(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "Tell me a joke"}],
)
print(response.choices[0].message.content)

Async usage

import litellm
from respan import Respan
from respan_instrumentation_litellm import LiteLLMInstrumentor
respan = Respan(instrumentations=[LiteLLMInstrumentor()])
response = await litellm.acompletion(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "Tell me a joke"}],
)