cool-lizard-26153
12/23/2025, 7:13 AMtall-airline-16756
12/23/2025, 7:14 AMtall-airline-16756
12/23/2025, 7:14 AMfrom livekit.agents.metrics import set_tracer_provider
set_tracer_provider("your-langfuse-public-key", "your-langfuse-secret-key", "<https://cloud.langfuse.com>")
This configures OpenTelemetry to send spans to Langfuse. It does not automatically capture payloads.
2) Instrument each pipeline node to log input/output
• Override the nodes in your Agent: stt_node, llm_node, and tts_node. Log inputs before processing and outputs after (or as chunks stream). Example for LLM:
from langfuse import current_run # or the Langfuse SDK object you use
from opentelemetry import trace
tracer = trace.get_tracer("livekit-agent")
async def llm_node(self, chat_ctx, tools, model_settings=None):
current_run.log_input({"chat_context": [m.dict() for m in chat_ctx.messages]})
with tracer.start_as_current_span("LLM_Inference") as span:
span.set_attribute("stage", "llm")
result_chunks = []
async for chunk in Agent.default.llm_node(self, chat_ctx, tools, model_settings):
# log each chunk as output
current_run.log_output({"content": getattr(chunk, "delta", getattr(chunk, "text", str(chunk)))})
span.add_event("llm_chunk", {"chunk": str(chunk)})
result_chunks.append(chunk)
yield chunk
span.set_attribute("llm_output", "".join([getattr(c, "delta", {}).get("content","") if hasattr(c, "delta") else str(c) for c in result_chunks]))
• Use the same pattern for stt_node (log raw audio metadata and transcript text) and tts_node (log input text and synthesized result or audio metadata).
3) Use spans and events for structured traces
• Wrap each stage in an OpenTelemetry span so Langfuse shows timing and attributes:
with tracer.start_as_current_span("STT") as span:
span.set_attribute("stage", "stt")
span.set_attribute("input_audio_length", audio_length)
# process and log transcript via current_run.log_output(...)
4) (Optional) Add global metadata via a span processor
• If you want user_id or session_id on every span, register a custom span processor that sets those attributes on span start. This will surface the metadata in Langfuse UI.
What I need from you if it still doesn’t work
• Which SDK/language are you using for the agent (Python or other)?
• Do you already see spans in Langfuse but no payload fields, or do you see nothing at all?
• Example snippet of your current `llm_node`/`stt_node`/`tts_node` (sanitized) if you want me to point out where to add logs.
I can give a tailored code snippet for your language and where to insert the log calls once you tell me the SDK and whether you see spans in Langfuse today.
Sources: Setting custom user_id and session_id in Langfuse traces | Pipeline nodes and hooks | LiveKit docs | Agents (Python) | livekit/livekit_composite | DeepWiki