Send Pydantic AI Traces to KloudMate
Pydantic AI has OpenTelemetry tracing built in, and its spans already follow the GenAI semantic conventions. Point an OTLP exporter at KloudMate and turn instrumentation on to see every agent run in AI Observability. You don’t need a Logfire account.
Prerequisites
Section titled “Prerequisites”- A KloudMate API key, from Settings → Ingest Keys.
- Pydantic AI 1.89 or later.
Install the packages
Section titled “Install the packages”Turn on instrumentation
Section titled “Turn on instrumentation”Set up a tracer provider with an OTLP exporter, then instrument every agent:
Call tracer_provider.shutdown() before a script exits, so the last spans are sent.
Point the exporter at KloudMate
Section titled “Point the exporter at KloudMate”OTLPSpanExporter() reads the standard OpenTelemetry variables. Set them in the environment that runs your app:
KloudMate expects the raw API key in the Authorization header, with no Bearer prefix. If the KloudMate agent runs on the same machine, set the endpoint to http://localhost:4318 and leave out the header.
Group a conversation
Section titled “Group a conversation”Pydantic AI sends a conversation ID automatically. A new run starts a new conversation, and a run that passes message_history from an earlier run continues it. To use your own chat or thread ID instead, pass conversation_id:
Control what’s captured
Section titled “Control what’s captured”Pydantic AI records prompts, responses, and tool arguments by default. To leave them out, pass InstrumentationSettings:
Token counts, models, and latency are still recorded. Pydantic AI also reports its own cost estimate on each call it can price, and KloudMate keeps that value instead of calculating one.
Check the data
Section titled “Check the data”Run the agent once, then open AI Observability → Traces. The run appears as a turn named after the agent, with its model, steps, tokens, and estimated cost.