Skip to main content

Respan exporter for Pydantic AI SDK

Project description

Respan Exporter for Pydantic AI

respan.ai · Documentation · PyPI

Instrument Pydantic AI agents with Respan: traces, spans, and metrics are sent to Respan via OpenTelemetry and standard semantic conventions. Requires respan-tracing (installed automatically).


Install

pip install respan-exporter-pydantic-ai

Environment Variables

Variable Required Description
RESPAN_API_KEY Yes Respan API key (used when api_key is not passed to RespanTelemetry)
RESPAN_BASE_URL No Respan API base URL (default: https://api.respan.ai/api)

Quickstart

import os
from pydantic_ai import Agent
from respan_tracing import RespanTelemetry
from respan_exporter_pydantic_ai.instrument import instrument_pydantic_ai

respan_api_key = os.environ["RESPAN_API_KEY"]
respan_base_url = os.getenv("RESPAN_BASE_URL", "https://api.respan.ai/api")

# Use Respan as the LLM gateway (no separate OpenAI key needed)
os.environ["OPENAI_BASE_URL"] = respan_base_url
os.environ["OPENAI_API_KEY"] = respan_api_key

# 1. Initialize Respan telemetry
telemetry = RespanTelemetry(app_name="my-app", api_key=respan_api_key)

# 2. Instrument Pydantic AI (global: all agents)
instrument_pydantic_ai()

# 3. Use your agent
agent = Agent("openai:gpt-4o")
result = agent.run_sync("What is the capital of France?")
print(result.output)

To instrument a single agent instead of globally:

agent = Agent("openai:gpt-4o")
instrument_pydantic_ai(agent=agent)

API Reference

RespanTelemetry

Initialize once before calling instrument_pydantic_ai():

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: True); set False for immediate flush in tests.

instrument_pydantic_ai()

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).

Traces appear in the Respan dashboard. Open a trace to see the workflow → task → LLM span tree.


Dev Guide

Setup

cd python-sdks/respan-exporter-pydantic-ai
poetry install

Tests

# Unit tests (no network)
poetry run pytest tests/test_instrument.py tests/test_extraction_functions.py -v

# All tests
poetry run pytest tests/ -v

# Integration test (real gateway, requires RESPAN_API_KEY)
IS_REAL_GATEWAY_TESTING_ENABLED=1 RESPAN_API_KEY="your-key" \
  poetry run pytest tests/test_real_gateway_integration.py -v -s

Run script (trace tree)

RESPAN_API_KEY="your-key" poetry run python scripts/run_real_gateway_test.py

Further Reading

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

respan_exporter_pydantic_ai-0.1.1.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

respan_exporter_pydantic_ai-0.1.1-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file respan_exporter_pydantic_ai-0.1.1.tar.gz.

File metadata

  • Download URL: respan_exporter_pydantic_ai-0.1.1.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.12.8 Darwin/25.2.0

File hashes

Hashes for respan_exporter_pydantic_ai-0.1.1.tar.gz
Algorithm Hash digest
SHA256 bbab80fb42ebb17d82e166e407370aa8158ab302ec5586ad7f30c68778399ff1
MD5 c8c38f962ef28721c5df8adc5d76d353
BLAKE2b-256 d1f15bc2453e9e48c19ef980534fe29ba6f37e17f4ec9ce2f572a62b1f0c4540

See more details on using hashes here.

File details

Details for the file respan_exporter_pydantic_ai-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for respan_exporter_pydantic_ai-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e06bbc2d33360d2b4897cb62cf2d073ae462f2fc6440fa3116f6308f1f3fdf31
MD5 913095d4a86317a0929c07695791a74d
BLAKE2b-256 227252e6ec86406a9be64cef6c96bfde2fa6e5bb9df642144cb6b5bb444a8a5a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page