Setup
Install the Braintrust SDK and Pydantic AI:Tracing Pydantic AI 2.0 or later requires the Braintrust Python SDK v0.26.0 or later.
Auto-instrumentation
To trace Pydantic AI without modifying each agent call, callinit_logger() and auto_instrument() once at startup. auto_instrument() patches Pydantic AI’s agent and model APIs along with every other supported library.Instrument only Pydantic AI
Instrument only Pydantic AI
To patch Pydantic AI without enabling Braintrust’s other integrations, call
setup_pydantic_ai() instead. It initializes a logger for you when one isn’t already active.Tools and streaming
Tools and streaming responses are traced without extra configuration:Nest under existing spans
If you already have a Braintrust span context (e.g., from@traced or start_span), Pydantic AI traces nest under it:OpenTelemetry
To trace Pydantic AI through an existing OpenTelemetry pipeline, attach aBraintrustSpanProcessor and enable Pydantic AI’s built-in instrumentation.1
Install packages
Install the Braintrust SDK with the OpenTelemetry extra, alongside Pydantic AI:
2
Configure tracing
Register the
BraintrustSpanProcessor with your tracer provider, then call Agent.instrument_all() to emit Pydantic AI’s instrumentation to Braintrust:What Braintrust traces
Braintrust captures:- Agent run spans (
agent_run,agent_run_sync,agent_run_stream,agent_run_stream_sync,agent_to_cli_sync), with the run input, agent metadata, output, and timing. - Direct model-request spans (
model_request,model_request_sync), forpydantic_ai.directAPI calls. - Model call spans (
chat <model>), for the underlying LLM calls made during a run. - Tool call spans, for tools invoked during an agent run.