Skip to main content
LangSmith can capture traces generated by PydanticAI using its built-in OpenTelemetry instrumentation. This guide shows you how to automatically capture traces from your PydanticAI agents and send them to LangSmith for monitoring and analysis.
In an agent-based workspace, create an agent once before sending traces. Use agent addressing to select its identifier and environment. If an integration requires project_name, use the selected environment’s tracer_session_name as a compatibility value.

Installation

Install the required packages:
Requires LangSmith Python SDK version langsmith>=0.4.26 for optimal OpenTelemetry support.

Setup

1. Configure environment variables

Set your API keys, agent identifier, and environment:

2. Configure OpenTelemetry integration

In your PydanticAI agent, configure the LangSmith OpenTelemetry integration:
You do not need to set any OpenTelemetry environment variables or configure exporters manually—configure() handles everything automatically.

3. Create and run your PydanticAI agent

Once configured, your PydanticAI agents will automatically send traces to LangSmith:

Advanced usage

Custom metadata and tags

You can add custom metadata to your traces using OpenTelemetry span attributes: