Hey can you help me with metrics tracing?
# ask-ai
c
Hey can you help me with metrics tracing?
t
Thanks for reaching out, Santiago. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
LiveKit offers some really helpful metrics and tracing features to keep an eye on your sessions. You can gather metrics live during agent sessions with the
metrics_collected
event, and tools like the
UsageCollector
make it easier to bring all that data together for you to analyze. When it comes to tracing, LiveKit supports OpenTelemetry, which means you can send trace data to platforms like Langfuse, Honeycomb, or Jaeger seamlessly. If you'd like a hand setting up metrics collection or getting OpenTelemetry tracing configured, just let me know which part you'd like to dive into, and I’ll be happy to walk you through it step-by-step. Sources: livekit/livekit_metrics.pb.go | docs/index.yaml | livekit-agents/livekit/agents/telemetry/__init__.py | Logs, metrics, and telemetry | LiveKit Docs | Logs, metrics, and telemetry | LiveKit docs
c
Im using from livekit.agents.telemetry import set_tracer_provider, but not all metric are being exported
t
Hi there! I wanted to share a bit about how the
set_tracer_provider
function in LiveKit works. It sets up OpenTelemetry tracing (spans) for you, but it doesn’t automatically export real-time metrics like STT, TTS, or LLM metrics. To make sure those metrics get exported, you’ll want to handle the
metrics_collected
event on the
AgentSession
or the individual components yourself. For instance, a simple way to log metrics locally is by using this example:
Copy code
from livekit.agents import metrics

@session.on("metrics_collected")
def _on_metrics_collected(ev):
    metrics.log_metrics(ev.metrics)
Another option is to aggregate metrics with the
UsageCollector
, or you could attach them to OpenTelemetry spans using
record_realtime_metrics
. If you'd like, I’m here to walk you through any of these methods or help troubleshoot if you’re running into any issues with your current setup. Just let me know! Sources: Logs, metrics, and telemetry | LiveKit docs | Logs, metrics, and telemetry | LiveKit Docs | metrics/send-metrics-to-3p/send_metrics_to_3p.py | livekit-agents/livekit/agents/telemetry/utils.py