Share via


AIAgentBuilderExtensions.UseOpenTelemetry Method

Definition

Adds OpenTelemetry instrumentation to the agent pipeline, enabling comprehensive observability for agent operations.

public static Microsoft.Agents.AI.AIAgentBuilder UseOpenTelemetry(this Microsoft.Agents.AI.AIAgentBuilder builder, string? sourceName = default, Action<Microsoft.Agents.AI.OpenTelemetryAgent>? configure = default);
static member UseOpenTelemetry : Microsoft.Agents.AI.AIAgentBuilder * string * Action<Microsoft.Agents.AI.OpenTelemetryAgent> -> Microsoft.Agents.AI.AIAgentBuilder
<Extension()>
Public Function UseOpenTelemetry (builder As AIAgentBuilder, Optional sourceName As String = Nothing, Optional configure As Action(Of OpenTelemetryAgent) = Nothing) As AIAgentBuilder

Parameters

builder
AIAgentBuilder

The AIAgentBuilder to which OpenTelemetry support will be added.

sourceName
String

An optional source name that will be used to identify telemetry data from this agent. If not specified, a default source name will be used.

configure
Action<OpenTelemetryAgent>

An optional callback that provides additional configuration of the OpenTelemetryAgent instance. This allows for fine-tuning telemetry behavior such as enabling sensitive data collection.

Returns

The AIAgentBuilder with OpenTelemetry instrumentation added, enabling method chaining.

Exceptions

builder is null.

Remarks

This extension adds comprehensive telemetry capabilities to AI agents, including:

  • Distributed tracing of agent invocations
  • Performance metrics and timing information
  • Request and response payload logging (when enabled)
  • Error tracking and exception details
  • Usage statistics and token consumption metrics

The implementation follows the OpenTelemetry Semantic Conventions for Generative AI systems as defined at https://opentelemetry.io/docs/specs/semconv/gen-ai/.

Note: The OpenTelemetry specification for Generative AI is still experimental and subject to change. As the specification evolves, the telemetry output from this agent may also change to maintain compliance.

Applies to