witty-kangaroo-6889
09/08/2025, 3:03 AMtall-airline-16756
09/08/2025, 3:03 AMtall-airline-16756
09/08/2025, 3:04 AMset_tracer_provider function.
2. Next, make sure to set these environment variables: LANGFUSE_PUBLIC_KEY, LANGFUSE_SECRET_KEY, and LANGFUSE_HOST.
3. Then, use the setup_langfuse() function in your entrypoint to kick off telemetry collection. This sets up the OpenTelemetry exporter to send data right to LangFuse.
Here’s a quick example for you:
import os
from livekit.agents.telemetry import set_tracer_provider
def setup_langfuse(host=None, public_key=None, secret_key=None):
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
public_key = public_key or os.getenv("LANGFUSE_PUBLIC_KEY")
secret_key = secret_key or os.getenv("LANGFUSE_SECRET_KEY")
host = host or os.getenv("LANGFUSE_HOST")
if not public_key or not secret_key or not host:
raise ValueError("LANGFUSE_PUBLIC_KEY, LANGFUSE_SECRET_KEY, and LANGFUSE_HOST must be set")
# Configuration continues...
Just so you know, metrics like TTFT (captured during LLM inference) and TTFB (captured during TTS generation) are automatically picked up and sent over to LangFuse. If you want to see a full example, check out the LiveKit Agents GitHub repository.
If you have any questions or need a hand with anything else, just give me a shout!
Sources: Logs, metrics, and telemetry | LiveKit Docs | Capturing metrics | LiveKit Docs | livekit-agents/livekit/agents/metrics/base.py | livekit/livekit_metrics.pb.go | Agent Testing & Evaluation | livekit/livekit_composite | DeepWiki