Pydantic AI
Pydantic AI (from the Pydantic team) has first-party, built-in OpenTelemetry instrumentation — it emits OTel GenAI spans natively, so there is no third-party instrumentor to install. Point a standard OTLP exporter at Neens and flip on instrumentation with one flag.
At a glance
| Language | Python |
| Instrumentation | Built-in (first-party OTel GenAI) |
| Endpoint | POST /v1/traces (OTLP/HTTP) |
| Auth | Authorization: Bearer nk_live_… agent key |
Instrument your agent
Install
Install Pydantic AI and the standard OpenTelemetry SDK + OTLP/HTTP exporter. No Neens SDK, no third-party instrumentor.
pip install pydantic-ai opentelemetry-sdk opentelemetry-exporter-otlpPoint OpenTelemetry at Neens
Configure a standard OTel TracerProvider with an OTLP exporter aimed at Neens, then enable Pydantic AI’s built-in instrumentation with instrument=True. No Logfire account required.
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from pydantic_ai import Agent
exporter = OTLPSpanExporter(
endpoint="https://<your-neens-host>/v1/traces",
headers={"Authorization": "Bearer nk_live_your_key_here"},
)
provider = TracerProvider()
provider.add_span_processor(BatchSpanProcessor(exporter))
trace.set_tracer_provider(provider)
# Enable Pydantic AI's built-in OTel instrumentation on this agent.
agent = Agent("openai:gpt-4o", instrument=True)To instrument every agent in your process at once, call Agent.instrument_all() after setting the tracer provider instead of passing instrument=True per agent.
Run your agent
Run your agent as usual — agent.run_sync("...") (or await agent.run("...")). Spans export to Neens in the background.
What Neens captures
Pydantic AI emits a span per agent run, with native OTel GenAI spans for every model call — model name, input/output token counts, and the prompt/response messages — plus a span per tool call. Together they give you the full agent trajectory. For multi-turn agents, set a conversation/session id on your runs so Neens groups them into one session (see Traces & sessions).
Neens speaks standard OTLP — this is not a Neens SDK fork. Any OpenTelemetry-configured Pydantic AI app exports to Neens by pointing its exporter at the endpoint above. Prefer Pydantic Logfire? It’s an optional convenience: call logfire.configure() (which sets the global tracer provider) with the same OTLP endpoint and headers, then logfire.instrument_pydantic_ai() — Neens reads either path, since it ingests OTel-GenAI and OpenInference attributes alike. See Send traces for the full attribute reference, size limits, and response codes.
Verify
Open Traces in Neens; your agent runs appear within a few seconds. Continue to Traces & sessions.