To trace PydanticAI agents with Phoenix, you must install and configure the OpenInference PydanticAI instrumentor and OpenTelemetry exporter correctly. Common errors often stem from missing or misconfigured environment variables, incorrect package versions, or issues with how input/output data is attached to spans. Ensure you use compatible versions of pydantic, pydantic-ai, and openinference-instrumentation-pydantic-ai, and that your tracing setup matches the documented example.
For setup, follow the official guide:
```
import os
from opentelemetry import trace
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.trace import TracerProvider
from openinference.instrumentation.pydantic_ai import OpenInferenceSpanProcessor
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
tracer_provider = TracerProvider()
trace.set_tracer_provider(tracer_provider)
endpoint = f"{os.environ['PHOENIX_COLLECTOR_ENDPOINT']}/v1/traces"
headers = {"Authorization": f"Bearer {os.environ['PHOENIX_API_KEY']}"}
exporter = OTLPSpanExporter(endpoint=endpoint, headers=headers)
tracer_provider.add_span_processor(OpenInferenceSpanProcessor())
tracer_provider.add_span_processor(SimpleSpanProcessor(exporter))
```
If you see missing input/output in the UI, check that your spans use the canonical keys `input.value` and `output.value` as required by Phoenix. If you encounter serialization errors, ensure your Pydantic version is > =2.7.2, as earlier versions have known issues with Phoenix integration. For more, see the <https://arize.com/docs/phoenix/integrations/pydantic/pydantic-tracing|official tracing guide> and <https://github.com/Arize-ai/openinference/issues/1984|troubleshooting tips>.
Would you like more detail or help with a specific error message?
Sources:
- <https://github.com/Arize-ai/openinference/issues/1984|PydanticAI auto-instrumentor troubleshooting>
- <https://github.com/Arize-ai/phoenix/issues/4310|Pydantic version compatibility issue>
- <https://arize.com/docs/phoenix/integrations/pydantic/pydantic-tracing|official tracing guide>