Overview
Userespan-exporter-pydantic-ai to instrument Pydantic AI agents with Respan. Traces, spans, and metrics from agent runs (including LLM calls and tool use) are sent to Respan via OpenTelemetry and standard semantic conventions. The exporter requires respan-tracing (installed automatically).
You can route LLM calls through Respan as the gateway, so only your Respan API key is needed—no separate OpenAI key.
Setup
1. InstallRESPAN_API_KEY (required). Optional: RESPAN_BASE_URL (default https://api.respan.ai/api). For the gateway pattern, also set OPENAI_BASE_URL and OPENAI_API_KEY to your Respan base URL and API key so no separate OpenAI key is needed.
Examples
Each example below is a complete runnable script. Run it and open the Respan dashboard to see the trace.Example: Hello World
Minimal instrumentation: initialize Respan, instrument Pydantic AI, run one agent call.
Example: Gateway
Use Respan as the LLM gateway and control content capture withinclude_content and include_binary_content.
Example: Workflows and tasks
Use@workflow and @task from respan-tracing to group spans into workflows and tasks.
Example: Respan params on spans
Setcustomer_identifier, metadata, and custom_tags on the current span with get_client().update_current_span(respan_params=...).
Example: Tool use
Agents that use tools are traced automatically; tool calls and results appear as spans.
Reference
RespanTelemetry options
| Argument | Description |
|---|---|
app_name | Application name shown in Respan. |
api_key | Optional if RESPAN_API_KEY is set. |
base_url | Optional; overrides RESPAN_BASE_URL. |
is_enabled | Set to False to disable tracing. |
is_batching_enabled | Batch export (default: typically True); set False for immediate flush in tests. |
instrument_pydantic_ai() options
| Argument | Description |
|---|---|
agent | Optional. If provided, only that agent is instrumented; if None, all agents are instrumented globally. |
include_content | Include message content in telemetry (default: True). |
include_binary_content | Include binary content in telemetry (default: True). |
Instrument a single agent
By default,instrument_pydantic_ai() instruments all Pydantic AI agents globally. To instrument only one agent:
Further reading
- Package: respan-exporter-pydantic-ai on PyPI
- Examples: Pydantic AI tracing examples — runnable scripts in the Respan example projects repo
- Respan: respan.ai, Documentation
- Pydantic AI: ai.pydantic.dev, Models (OpenAI)
- respan-tracing: PyPI — decorators (
@workflow,@task), manual spans, and export options