Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ METRICS:
AgentSession emits a metrics_collected event with detailed metrics including VAD metrics like idle time and inference duration, STT metrics like audio duration, EOU metrics like end of utterance delay and transcription delay, LLM metrics like token counts and time to first token, and TTS metrics like audio duration and time to first byte. Total conversation latency can be approximated as end_of_utterance_delay plus LLM time to first token plus TTS time to first byte. You can also use UsageCollector to aggregate LLM, TTS, and STT usage for cost estimation.

OPENTELEMETRY:
The Python SDK supports OpenTelemetry integration. You can set a tracer provider to export spans to any OpenTelemetry-compatible backend like LangFuse.
The Python SDK supports OpenTelemetry integration. You can set a tracer provider to export spans to any OpenTelemetry-compatible backend, including Arize AX, Langfuse, Jaeger, Grafana Tempo, and Honeycomb.

SHARING WITH SUPPORT:
You can share specific session insights with LiveKit support on Ship plan or higher. Enable sharing from the session's Agent Insights tab to generate a link you can email to support.
15 changes: 13 additions & 2 deletions examples/voice_agents/otel_trace.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging

from dotenv import load_dotenv
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.util.types import AttributeValue

Expand All @@ -27,7 +28,7 @@

# This example shows how to trace the agent session with OpenTelemetry.
# It exports spans over OTLP/HTTP, so it works with any OTLP-compatible backend
# (Langfuse, Jaeger, Grafana Tempo, Honeycomb, etc.). To enable tracing, set the trace
# (Arize AX, Langfuse, Jaeger, Grafana Tempo, Honeycomb, etc.). To enable tracing, set the trace
# provider with `set_tracer_provider` at the module level or inside the entrypoint
# before `AgentSession.start()`.
#
Expand All @@ -45,20 +46,30 @@
# headers={"Authorization": f"Basic {auth}", "x-langfuse-ingestion-version": "4"},
# )
# Refer to their docs for latest instructions: https://langfuse.com/integrations/native/opentelemetry#opentelemetry-endpoint
#
# Worked example — Arize AX: the endpoint is `https://otlp.arize.com/v1/traces`.
# Pass your Space ID and API key as OTLP headers, and set the project name as a resource attribute:
# setup_otel(
# endpoint="https://otlp.arize.com/v1/traces",
# headers={"space_id": space_id, "api_key": api_key},
# resource_attributes={"openinference.project.name": "livekit-agent"},
# )
# Refer to the Arize guide for the full LiveKit setup: https://arize.com/docs/ax/integrations/python-agent-frameworks/livekit/livekit-agents-tracing


def setup_otel(
metadata: dict[str, AttributeValue] | None = None,
*,
endpoint: str | None = None,
headers: dict[str, str] | None = None,
resource_attributes: dict[str, AttributeValue] | None = None,
) -> TracerProvider:
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.trace.export import BatchSpanProcessor

# When endpoint/headers are None, the exporter falls back to the standard
# OTEL_EXPORTER_OTLP_* environment variables.
trace_provider = TracerProvider()
trace_provider = TracerProvider(resource=Resource.create(resource_attributes or {}))
trace_provider.add_span_processor(
BatchSpanProcessor(OTLPSpanExporter(endpoint=endpoint, headers=headers))
)
Expand Down