Skip to main content
LiveKit Agents is a framework for building real-time voice and video AI applications. Braintrust traces LiveKit Agents applications using OpenTelemetry to capture voice interactions, agent sessions, and realtime model usage.

Setup

pip install "braintrust[otel]" livekit-agents livekit-plugins-openai opentelemetry-sdk
The @braintrust/otel package supports both OpenTelemetry v1 and v2. For the best experience, use the same OpenTelemetry versions that LiveKit Agents uses to avoid compatibility issues.
Configure your environment variables:
.env
BRAINTRUST_API_KEY=your-api-key
BRAINTRUST_PARENT=project_name:livekit-demo
OPENAI_API_KEY=your-openai-api-key

Trace with LiveKit Agents

Configure Braintrust’s span processor and set it as LiveKit’s tracer provider.
livekit_agent.py
from braintrust.otel import BraintrustSpanProcessor
from livekit import agents
from livekit.agents import Agent, AgentSession, RoomInputOptions
from livekit.agents.telemetry import set_tracer_provider
from livekit.plugins import noise_cancellation, openai
from opentelemetry.sdk.trace import TracerProvider

def setup_braintrust_telemetry():
    """Setup Braintrust OTEL telemetry for agent monitoring"""
    trace_provider = TracerProvider()
    trace_provider.add_span_processor(BraintrustSpanProcessor())
    set_tracer_provider(trace_provider)

class Assistant(Agent):
    def __init__(self) -> None:
        super().__init__(instructions="You are a helpful voice AI assistant.")

async def entrypoint(ctx: agents.JobContext):
    # Setup telemetry
    setup_braintrust_telemetry()

    # Create agent session with OpenAI realtime model
    session = AgentSession(llm=openai.realtime.RealtimeModel(voice="coral"))

    # Start session with assistant agent
    await session.start(
        room=ctx.room,
        agent=Assistant(),
        room_input_options=RoomInputOptions(
            noise_cancellation=noise_cancellation.BVC(),
        ),
    )

# Run script locally with `python livekit_agent.py console`
if __name__ == "__main__":
    agents.cli.run_app(agents.WorkerOptions(entrypoint_fnc=entrypoint))
The BraintrustSpanProcessor automatically captures all LiveKit agent spans, including:
  • Voice interactions and audio processing
  • OpenAI Realtime API calls
  • Agent session lifecycle events
  • Custom spans you create with tracer.start_as_current_span() (Python) or tracer.startActiveSpan() (TypeScript)
You can add attributes to spans using span.set_attribute() (Python) or span.setAttribute() (TypeScript) to enrich your traces with custom metadata, making it easier to debug and analyze your agent’s behavior in Braintrust.

Next steps

Learn more about building with LiveKit Agents and tracing with Braintrust: LiveKit Agents Braintrust Tracing