gifted-quill-68253
10/22/2025, 1:08 PMtall-airline-16756
10/22/2025, 1:08 PMtall-airline-16756
10/22/2025, 1:10 PMgifted-quill-68253
10/22/2025, 1:12 PMtall-airline-16756
10/22/2025, 1:14 PMNEW_RELIC_LICENSE_KEY as an environment variable or secret in your deployment environment. For example:
# Environment Variable Method
export NEW_RELIC_LICENSE_KEY="your_license_key_here"
# Docker Environment
ENV NEW_RELIC_LICENSE_KEY="your_license_key_here"
# Kubernetes Secret
apiVersion: v1
kind: Secret
metadata:
name: agent-secrets
type: Opaque
stringData:
NEW_RELIC_LICENSE_KEY: "your_license_key_here"
Once you have this set up, all your runtime logs (including stdout/stderr) will be automatically sent over to New Relic, making things much smoother!
2. OpenTelemetry for Traces
If you want to send traces and spans, you can configure OpenTelemetry right in your agent's entrypoint like this:
from livekit.agents.telemetry import set_tracer_provider
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
def setup_telemetry():
trace_provider = TracerProvider()
otlp_exporter = OTLPSpanExporter(
endpoint="http://your-otel-collector:4318/v1/traces",
headers={"Authorization": "Bearer your-token"} # if required
)
trace_provider.add_span_processor(BatchSpanProcessor(otlp_exporter))
set_tracer_provider(trace_provider)
return trace_provider
Just plug this setup into your agent's main entrypoint, and you’ll be able to capture traces for session activities, LLM operations, and more. It’s a great way to keep an eye on what’s happening under the hood!
Additional Notes
• Make sure your network can reach New Relic's ingestion endpoints and your OpenTelemetry collector without any hiccups.
• If things aren’t working as expected, double-check that your NEW_RELIC_LICENSE_KEY is set correctly and accessible.
• OpenTelemetry can also handle logs, but that involves a bit more setup beyond what’s shown here.
If you have any questions or want a hand with specific configuration steps, please don’t hesitate to reach out—I’m here to help!
Sources: Logs, metrics, and telemetry | LiveKit Docs | Log collection | LiveKit Docs | livekit-agents/livekit/agents/voice/agent_activity.pygifted-quill-68253
10/23/2025, 12:20 PMtall-airline-16756
10/23/2025, 12:21 PM@agent.on("metrics_collected")
async def on_metrics_collected(metrics: AgentMetrics):
print(logMetrics(metrics))
This way, you’ll be capturing important data like LLM, STT, TTS, VAD, and EOU during your sessions.
2. Exporting Metrics to Third-Party Systems
If you want to send these metrics to an external system, you can create an event handler that converts the metrics to JSON and sends them via HTTP. Here’s a simple example:
# Use async HTTP requests to send metrics to an external server
async def export_metrics(metrics):
async with aiohttp.ClientSession() as session:
await session.post("<YOUR_METRICS_SERVER_URL>", json=metrics)
3. Aggregating Usage Metrics
To get a bigger picture, you can use the UsageCollector class to gather metrics across a session—this is really helpful for estimating costs and analyzing performance:
collector = UsageCollector()
collector.add_metrics(metrics)
summary = collector.build_summary()
4. OpenTelemetry Integration
For even deeper insights, you might consider integrating with OpenTelemetry. This lets you trace agent session flows and node-level operations, and you can combine it with third-party tools like Langfuse for advanced analysis.
If you’d like to explore more, feel free to check out the LiveKit Python Agents Examples repository and the LiveKit Agents Metrics documentation.
I'm here to help, so please don’t hesitate to reach out if you want any help with specific setups or code examples!
Sources: livekit/livekit_metrics.pb.go | lib/livekit/proto/livekit_metrics_pb.rb | livekit-protocol/livekit/protocol/metrics.py | LiveKit Pricing | docs/index.yaml