Learn how to instrument PydanticAI applications with the LangWatch Python SDK.
langwatch.setup()
.
langwatch.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)
or Agent.instrument_all()
: Activates PydanticAI’s OpenTelemetry signal emission.InstrumentationSettings(event_mode='logs')
: As per PydanticAI documentation, using event_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.