Skip to content

.NET: Workflow telemetry opt in#3467

Open
TaoChenOSU wants to merge 15 commits intomicrosoft:mainfrom
TaoChenOSU:feature/workflow-telemetry-opt-in
Open

.NET: Workflow telemetry opt in#3467
TaoChenOSU wants to merge 15 commits intomicrosoft:mainfrom
TaoChenOSU:feature/workflow-telemetry-opt-in

Conversation

@TaoChenOSU
Copy link
Contributor

@TaoChenOSU TaoChenOSU commented Jan 27, 2026

Motivation and Context

Closes #3386

Foundry observability team has requested the following features from AF workflow telemetry:

  1. Rename workflow.run to workflow_invoke
  2. Add executor input/output attrs to executor activities
  3. Configuration on what activities to create
  4. Add executor id to executor.process activities

Description

  1. Rename workflow.run to workflow_invoke
  2. Add executor input/output attrs to executor activities. Note that if a handler doesn't return a value, the handler outputs its results via SendMessage, where the messages will be added as attributes in the message.send activities.
  3. Configuration on what activities to create. These include EnableSensitiveData, and disabling activities from workflows.
  4. Add executor id to executor.process activities

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

- Add WorkflowTelemetryOptions class with EnableSensitiveData property
- Add WorkflowTelemetryContext to manage ActivitySource lifecycle
- Add WithOpenTelemetry() extension method on WorkflowBuilder
- Update all workflow components to use telemetry context:
  - WorkflowBuilder, Workflow, Executor
  - InProcessRunnerContext, InProcessRunner
  - LockstepRunEventStream, StreamingRunEventStream
  - All edge runners (Direct, FanIn, FanOut, Response)
- Telemetry is now disabled by default
- Users must call WithOpenTelemetry() to enable spans/activities

BREAKING CHANGE: Workflow telemetry is now opt-in. Users who relied on
automatic telemetry must add .WithOpenTelemetry() to their workflow builder.
- Remove IWorkflowContextWithTelemetry interface
- Add internal ExecuteAsync overload that accepts WorkflowTelemetryContext
- Public ExecuteAsync delegates with WorkflowTelemetryContext.Disabled
- InProcessRunner passes TelemetryContext when calling ExecuteAsync
- BoundContext now implements IWorkflowContext (not the removed interface)
Allow users to provide their own ActivitySource when enabling telemetry,
giving them better control over the ActivitySource lifecycle. When not
provided, the framework creates one internally (existing behavior).

Changes:
- Add optional activitySource parameter to WithOpenTelemetry() extension
- Update WorkflowTelemetryContext to accept external ActivitySource
- Add unit test for user-provided ActivitySource scenario
Allow users to selectively disable specific activity types via
WorkflowTelemetryOptions. All activities are enabled by default.

New disable flags:
- DisableWorkflowBuild: Disables workflow.build activities
- DisableWorkflowRun: Disables workflow_invoke activities
- DisableExecutorProcess: Disables executor.process activities
- DisableEdgeGroupProcess: Disables edge_group.process activities
- DisableMessageSend: Disables message.send activities

Added helper methods to WorkflowTelemetryContext for each activity type
and updated all activity creation sites to use them.
When EnableSensitiveData is true in WorkflowTelemetryOptions, executor
input and output are logged as JSON-serialized attributes in the
executor.process activity.

New activity tags:
- executor.input: JSON serialized input message
- executor.output: JSON serialized output result (non-void only)

Added suppression attributes for AOT/trimming warnings since this is
an opt-in feature for debugging/diagnostics.
Move tagging logic into WorkflowTelemetryContext methods:
- StartExecutorProcessActivity now accepts executorId, executorType,
  messageType, and message; sets all tags including executor.input
  when EnableSensitiveData is true
- Added SetExecutorOutput method to set executor.output after execution
- StartMessageSendActivity now accepts sourceId, targetId, and message;
  sets all tags including message.content when EnableSensitiveData is true

Simplified Executor.cs and InProcessRunnerContext.cs by removing
inline tagging code. Added message.content tag constant.
@TaoChenOSU TaoChenOSU self-assigned this Jan 27, 2026
@TaoChenOSU TaoChenOSU added .NET workflows Related to Workflows in agent-framework observability Issues related to observability or telemetry labels Jan 27, 2026
@TaoChenOSU TaoChenOSU moved this to In Review in Agent Framework Jan 27, 2026
@github-actions github-actions bot changed the title Workflow telemetry opt in .NET: Workflow telemetry opt in Jan 27, 2026
@TaoChenOSU TaoChenOSU marked this pull request as ready for review February 6, 2026 05:19
Copilot AI review requested due to automatic review settings February 6, 2026 05:19
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request implements opt-in telemetry for .NET workflows with comprehensive configuration options. The PR addresses requirements from the Foundry observability team to improve workflow telemetry capabilities while making it configurable and privacy-conscious.

Changes:

  • Introduced opt-in telemetry via WithOpenTelemetry() extension method on WorkflowBuilder (telemetry is now disabled by default)
  • Renamed workflow run activity from workflow.run to workflow_invoke for consistency with telemetry naming conventions
  • Added executor input/output attributes to executor activities (when EnableSensitiveData is true)
  • Implemented granular telemetry configuration through WorkflowTelemetryOptions (disable specific activities, enable sensitive data logging)
  • Added executor ID to executor.process activity names for better traceability

Reviewed changes

Copilot reviewed 28 out of 28 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
OpenTelemetryWorkflowBuilderExtensions.cs New public API for enabling workflow telemetry with fluent configuration
WorkflowTelemetryOptions.cs Configuration class for controlling telemetry behavior (sensitive data, activity toggles)
WorkflowTelemetryContext.cs Internal context managing telemetry state and creating activities with appropriate tags
ActivityNames.cs Renamed WorkflowRun constant from "workflow.run" to "workflow_invoke"
Tags.cs Added ExecutorInput, ExecutorOutput, and MessageContent tag constants
WorkflowBuilder.cs Integrated telemetry context and removed static ActivitySource
Workflow.cs Added TelemetryContext property
Executor.cs Updated to use telemetry context and log input/output when enabled
InProcessRunner.cs Pass telemetry context to executor execution
InProcessRunnerContext.cs Use telemetry context for message send activities
IRunnerContext.cs Added TelemetryContext property to interface
ISuperStepRunner.cs Added TelemetryContext property to interface
StreamingRunEventStream.cs Removed static ActivitySource, use telemetry context
LockstepRunEventStream.cs Removed static ActivitySource, use telemetry context
EdgeRunner.cs Added helper method for starting edge activities (has bug)
DirectEdgeRunner.cs Use helper method from base class
FanInEdgeRunner.cs Use helper method from base class
FanOutEdgeRunner.cs Use helper method from base class
ResponseEdgeRunner.cs Use helper method from base class
DeclarativeWorkflowOptions.cs Added telemetry configuration properties
WorkflowActionVisitor.cs Apply telemetry configuration to declarative workflows with validation
ObservabilityTests.cs Comprehensive test coverage for all telemetry features
DeclarativeWorkflowOptionsTest.cs Tests for declarative workflow telemetry configuration
TestRunContext.cs Updated test infrastructure to support telemetry context
CosmosDBCollectionFixture.cs Removed redundant using statement (global using in place)
AspireDashboard/Program.cs Updated sample to demonstrate opt-in telemetry with sensitive data enabled
ApplicationInsights/Program.cs Updated sample to demonstrate opt-in telemetry with sensitive data enabled
FoundryAgents_Step01.1_Basics/Program.cs Removed unused import

Copy link
Contributor

@crickman crickman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the unit test!

@TaoChenOSU TaoChenOSU enabled auto-merge February 6, 2026 19:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

.NET observability Issues related to observability or telemetry workflows Related to Workflows in agent-framework

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

.NET: [Feature]: Workflow telemetry Opt-in

2 participants