OpenTelemetryWorkflowBuilderExtensions.WithOpenTelemetry Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Enables OpenTelemetry instrumentation for the workflow, providing comprehensive observability for workflow operations.
public static Microsoft.Agents.AI.Workflows.WorkflowBuilder WithOpenTelemetry(this Microsoft.Agents.AI.Workflows.WorkflowBuilder builder, Action<Microsoft.Agents.AI.Workflows.Observability.WorkflowTelemetryOptions>? configure = default, System.Diagnostics.ActivitySource? activitySource = default);
static member WithOpenTelemetry : Microsoft.Agents.AI.Workflows.WorkflowBuilder * Action<Microsoft.Agents.AI.Workflows.Observability.WorkflowTelemetryOptions> * System.Diagnostics.ActivitySource -> Microsoft.Agents.AI.Workflows.WorkflowBuilder
<Extension()>
Public Function WithOpenTelemetry (builder As WorkflowBuilder, Optional configure As Action(Of WorkflowTelemetryOptions) = Nothing, Optional activitySource As ActivitySource = Nothing) As WorkflowBuilder
Parameters
- builder
- WorkflowBuilder
The WorkflowBuilder to which OpenTelemetry support will be added.
- configure
- Action<WorkflowTelemetryOptions>
An optional callback that provides additional configuration of the WorkflowTelemetryOptions instance. This allows for fine-tuning telemetry behavior such as enabling sensitive data collection.
- activitySource
- ActivitySource
An optional ActivitySource to use for telemetry. If provided, this activity source will be used
directly and the caller retains ownership (responsible for disposal). If null, a shared
default activity source named "Microsoft.Agents.AI.Workflows" will be used.
Returns
The WorkflowBuilder with OpenTelemetry instrumentation enabled, enabling method chaining.
Exceptions
builder is null.
Examples
var workflow = new WorkflowBuilder(startExecutor)
.AddEdge(executor1, executor2)
.WithOpenTelemetry(cfg => cfg.EnableSensitiveData = true)
.Build();
Remarks
This extension adds comprehensive telemetry capabilities to workflows, including:
- Distributed tracing of workflow execution
- Executor invocation and processing spans
- Edge routing and message delivery spans
- Workflow build and validation spans
- Error tracking and exception details
By default, workflow telemetry is disabled. Call this method to enable telemetry collection.