Learn how to instrument LiteLLM calls with the LangWatch Python SDK.
autotrack_litellm_calls()
: This method, part of the LangWatch SDK, dynamically patches your LiteLLM module instance for the current trace to capture its calls.langwatch.setup()
) is active.openai
SDK for OpenAI models), you can leverage community instrumentors for those specific underlying SDKs.autotrack_litellm_calls()
autotrack_litellm_calls()
function, called on a trace object, provides a straightforward way to capture all LiteLLM calls for the duration of the current trace. This is often the most direct way to ensure LiteLLM operations are captured by LangWatch within a specific traced function.
You typically call this method on the trace object obtained via langwatch.get_current_trace()
inside a function decorated with @langwatch.trace()
.
autotrack_litellm_calls()
:
langwatch.get_current_trace()
).litellm
module instance specifically for the current trace.LiteLLMInstrumentor
from openinference.instrumentation.litellm
to the instrumentors
list in langwatch.setup()
.
langwatch.setup()
LiteLLMInstrumentor
from openinference.instrumentation.litellm
to the instrumentors
list in langwatch.setup()
.
openinference-instrumentation-litellm
library installed.LiteLLMInstrumentor
instrument()
on an instance of LiteLLMInstrumentor
.
LiteLLMInstrumentor
:
autotrack_litellm_calls
if you prefer an explicit instrumentor pattern or are using OpenInference across your stack.autotrack_litellm_calls()
: Best for explicit, trace-specific instrumentation of LiteLLM. Offers clear control over when LiteLLM calls are tracked by LangWatch within a given trace.LiteLLMInstrumentor
: Use if you are standardizing on OpenInference instrumentors or prefer this explicit way of instrumenting LiteLLM itself (rather than its underlying SDKs). It provides traces directly from LiteLLM’s perspective.