Prerequisites
-
Install LangWatch SDK:
-
Install PydanticAI:
Instrumenting PydanticAI with LangWatch
The primary way to integrate PydanticAI with LangWatch is by leveraging PydanticAI’s native OpenTelemetry emission in an environment configured bylangwatch.setup()
.
Using PydanticAI’s Built-in OpenTelemetry with LangWatch Global Setup
Whenlangwatch.setup()
is called, it initializes a global OpenTelemetry environment, including a trace exporter configured for LangWatch. If PydanticAI’s instrumentation is enabled (via Agent(instrument=True)
or Agent.instrument_all()
), it will emit OpenTelemetry traces that are automatically captured by LangWatch.
langwatch.setup()
: Essential for initializing the OpenTelemetry environment that LangWatch uses.Agent(instrument=True)
orAgent.instrument_all()
: Activates PydanticAI’s OpenTelemetry signal emission.InstrumentationSettings(event_mode='logs')
: As per PydanticAI documentation, usingevent_mode='logs'
aligns message capture with OpenTelemetry Semantic Conventions for Generative AI, which might be better for generic OTel collectors. The default mode (json_array
) uses a custom attribute format for events.@langwatch.trace()
: Creates a parent trace in LangWatch, under which PydanticAI’s operation spans will be nested.