how to trace the llm request and response using la...
# ask-ai
w
how to trace the llm request and response using langfuse?
t
Thanks for reaching out, Sunil. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! If you want to trace LLM requests and responses using Langfuse, you’ll need to set up LiveKit’s OpenTelemetry integration to send telemetry data over to Langfuse. Here’s a simple way to get started: 1. First, make sure you have the necessary environment variables set up:
LANGFUSE_PUBLIC_KEY
,
LANGFUSE_SECRET_KEY
, and
LANGFUSE_HOST
. 2. Next, call the
setup_langfuse()
function right in your entry point. This will initialize the tracer provider and configure OpenTelemetry to send spans to Langfuse through the OTLP endpoint. Once that’s all set up, the system will automatically trace your LLM requests and responses: • For each LLM inference, an
llm_request
span is created, capturing helpful details like the request model, input/output token usage, and timing info. • The entire LLM request, including chat context messages, gets recorded as OpenTelemetry events like
gen_ai.user.message
and
gen_ai.assistant.message
. • The response, including generated text and any tool calls, is captured as an event named
gen_ai.choice
. All this data follows OpenTelemetry’s GenAI conventions and you can explore it easily in the Langfuse dashboard. If you want to see it in action, there’s a complete working example waiting for you in the LiveKit Agents GitHub repository. Sources: Logs, metrics, and telemetry | LiveKit Docs | livekit-plugins/livekit-plugins-google/livekit/plugins/google/llm.py