diff --git a/dotnet/samples/03-workflows/Observability/ApplicationInsights/Program.cs b/dotnet/samples/03-workflows/Observability/ApplicationInsights/Program.cs index 0a7e1b813bf..18fb57c8f61 100644 --- a/dotnet/samples/03-workflows/Observability/ApplicationInsights/Program.cs +++ b/dotnet/samples/03-workflows/Observability/ApplicationInsights/Program.cs @@ -54,10 +54,7 @@ private static async Task Main() // Build the workflow by connecting executors sequentially var workflow = new WorkflowBuilder(uppercase) .AddEdge(uppercase, reverse) - .WithOpenTelemetry( - // Set `EnableSensitiveData` to true to include message content in traces - configure: cfg => cfg.EnableSensitiveData = true, - activitySource: s_activitySource) + .WithOpenTelemetry(activitySource: s_activitySource) .Build(); // Execute the workflow with input data diff --git a/dotnet/samples/03-workflows/Observability/AspireDashboard/Program.cs b/dotnet/samples/03-workflows/Observability/AspireDashboard/Program.cs index 890b384422f..56751d14d2c 100644 --- a/dotnet/samples/03-workflows/Observability/AspireDashboard/Program.cs +++ b/dotnet/samples/03-workflows/Observability/AspireDashboard/Program.cs @@ -56,10 +56,7 @@ private static async Task Main() // Build the workflow by connecting executors sequentially var workflow = new WorkflowBuilder(uppercase) .AddEdge(uppercase, reverse) - .WithOpenTelemetry( - // Set `EnableSensitiveData` to true to include message content in traces - configure: cfg => cfg.EnableSensitiveData = true, - activitySource: s_activitySource) + .WithOpenTelemetry(activitySource: s_activitySource) .Build(); // Execute the workflow with input data diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows/Executor.cs b/dotnet/src/Microsoft.Agents.AI.Workflows/Executor.cs index a89791b4244..dfa863379a5 100644 --- a/dotnet/src/Microsoft.Agents.AI.Workflows/Executor.cs +++ b/dotnet/src/Microsoft.Agents.AI.Workflows/Executor.cs @@ -262,7 +262,7 @@ protected internal virtual ValueTask InitializeAsync(IWorkflowContext context, C internal async ValueTask ExecuteCoreAsync(object message, TypeId messageType, IWorkflowContext context, WorkflowTelemetryContext telemetryContext, CancellationToken cancellationToken = default) { - using var activity = telemetryContext.StartExecutorProcessActivity(this.Id, this.GetType().FullName, messageType.TypeName, message); + using var activity = telemetryContext.StartExecutorProcessActivity(this.Id, this.GetType().FullName, messageType.TypeName); activity?.CreateSourceLinks(context.TraceContext); await context.AddEventAsync(new ExecutorInvokedEvent(this.Id, message), cancellationToken).ConfigureAwait(false); @@ -298,11 +298,6 @@ protected internal virtual ValueTask InitializeAsync(IWorkflowContext context, C return null; // Void result. } - // Output is not available if executor does not return anything, in which case - // messages sent in the handlers of this executor will be set in the message - // send activities. - telemetryContext.SetExecutorOutput(activity, result.Result); - // If we had a real return type, raise it as a SendMessage; TODO: Should we have a way to disable this behaviour? if (result.Result is not null && this.Options.AutoSendMessageHandlerResultObject) { diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows/InProc/InProcessRunnerContext.cs b/dotnet/src/Microsoft.Agents.AI.Workflows/InProc/InProcessRunnerContext.cs index f2e4f8408ba..391b35a9afa 100644 --- a/dotnet/src/Microsoft.Agents.AI.Workflows/InProc/InProcessRunnerContext.cs +++ b/dotnet/src/Microsoft.Agents.AI.Workflows/InProc/InProcessRunnerContext.cs @@ -214,7 +214,7 @@ public ValueTask AddEventAsync(WorkflowEvent workflowEvent, CancellationToken ca public async ValueTask SendMessageAsync(string sourceId, object message, string? targetId = null, CancellationToken cancellationToken = default) { - using Activity? activity = this._workflow.TelemetryContext.StartMessageSendActivity(sourceId, targetId, message); + using Activity? activity = this._workflow.TelemetryContext.StartMessageSendActivity(sourceId, targetId); // Create a carrier for trace context propagation var traceContext = activity is null ? null : new Dictionary(); diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows/Observability/Tags.cs b/dotnet/src/Microsoft.Agents.AI.Workflows/Observability/Tags.cs index 151d15137e6..56b3ecd3f13 100644 --- a/dotnet/src/Microsoft.Agents.AI.Workflows/Observability/Tags.cs +++ b/dotnet/src/Microsoft.Agents.AI.Workflows/Observability/Tags.cs @@ -17,10 +17,7 @@ internal static class Tags public const string SessionId = "session.id"; public const string ExecutorId = "executor.id"; public const string ExecutorType = "executor.type"; - public const string ExecutorInput = "executor.input"; - public const string ExecutorOutput = "executor.output"; public const string MessageType = "message.type"; - public const string MessageContent = "message.content"; public const string EdgeGroupType = "edge_group.type"; public const string MessageSourceId = "message.source_id"; public const string MessageTargetId = "message.target_id"; diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows/Observability/WorkflowTelemetryContext.cs b/dotnet/src/Microsoft.Agents.AI.Workflows/Observability/WorkflowTelemetryContext.cs index 7794eb4f1a7..4ec4e3bc0ba 100644 --- a/dotnet/src/Microsoft.Agents.AI.Workflows/Observability/WorkflowTelemetryContext.cs +++ b/dotnet/src/Microsoft.Agents.AI.Workflows/Observability/WorkflowTelemetryContext.cs @@ -1,9 +1,6 @@ // Copyright (c) Microsoft. All rights reserved. -using System; using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; -using System.Text.Json; using OpenTelemetry; namespace Microsoft.Agents.AI.Workflows.Observability; @@ -146,9 +143,8 @@ public WorkflowTelemetryContext(WorkflowTelemetryOptions options, ActivitySource /// The executor identifier. /// The executor type name. /// The message type name. - /// The input message. Logged only when is true. /// An activity if executor process telemetry is enabled, otherwise null. - public Activity? StartExecutorProcessActivity(string executorId, string? executorType, string messageType, object? message) + public Activity? StartExecutorProcessActivity(string executorId, string? executorType, string messageType) { if (!this.IsEnabled || this.Options.DisableExecutorProcess) { @@ -165,27 +161,9 @@ public WorkflowTelemetryContext(WorkflowTelemetryOptions options, ActivitySource .SetTag(Tags.ExecutorType, executorType) .SetTag(Tags.MessageType, messageType); - if (this.Options.EnableSensitiveData) - { - activity.SetTag(Tags.ExecutorInput, SerializeForTelemetry(message)); - } - return activity; } - /// - /// Sets the executor output tag on an activity when sensitive data logging is enabled. - /// - /// The activity to set the output on. - /// The output value to log. - public void SetExecutorOutput(Activity? activity, object? output) - { - if (activity is not null && this.Options.EnableSensitiveData) - { - activity.SetTag(Tags.ExecutorOutput, SerializeForTelemetry(output)); - } - } - /// /// Starts an edge group process activity if enabled. /// @@ -205,9 +183,8 @@ public void SetExecutorOutput(Activity? activity, object? output) /// /// The source executor identifier. /// The target executor identifier, if any. - /// The message being sent. Logged only when is true. /// An activity if message send telemetry is enabled, otherwise null. - public Activity? StartMessageSendActivity(string sourceId, string? targetId, object? message) + public Activity? StartMessageSendActivity(string sourceId, string? targetId) { if (!this.IsEnabled || this.Options.DisableMessageSend) { @@ -226,33 +203,6 @@ public void SetExecutorOutput(Activity? activity, object? output) activity.SetTag(Tags.MessageTargetId, targetId); } - if (this.Options.EnableSensitiveData) - { - activity.SetTag(Tags.MessageContent, SerializeForTelemetry(message)); - } - return activity; } - - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL3050:RequiresDynamicCode", Justification = "Telemetry serialization is optional and only used when explicitly enabled.")] - [UnconditionalSuppressMessage("Trimming", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access", Justification = "Telemetry serialization is optional and only used when explicitly enabled.")] - private static string? SerializeForTelemetry(object? value) - { - if (value is null) - { - return null; - } - - try - { - return JsonSerializer.Serialize(value, value.GetType()); - } - // Telemetry must never fail workflow execution. Serialization can throw arbitrary exceptions - // (unregistered polymorphic types, reflection-disabled AOT, throwing property getters, custom - // converters), so fall back for every serialization failure. - catch (Exception) - { - return $"[Unserializable: {value.GetType().FullName}]"; - } - } } diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows/Observability/WorkflowTelemetryOptions.cs b/dotnet/src/Microsoft.Agents.AI.Workflows/Observability/WorkflowTelemetryOptions.cs index 17b9af54d9f..67a39c7a9a9 100644 --- a/dotnet/src/Microsoft.Agents.AI.Workflows/Observability/WorkflowTelemetryOptions.cs +++ b/dotnet/src/Microsoft.Agents.AI.Workflows/Observability/WorkflowTelemetryOptions.cs @@ -1,5 +1,7 @@ // Copyright (c) Microsoft. All rights reserved. +using System; + namespace Microsoft.Agents.AI.Workflows.Observability; /// @@ -8,17 +10,16 @@ namespace Microsoft.Agents.AI.Workflows.Observability; public sealed class WorkflowTelemetryOptions { /// - /// Gets or sets a value indicating whether potentially sensitive information should be included in telemetry. + /// Gets or sets a legacy option that no longer affects workflow telemetry. /// /// - /// if potentially sensitive information should be included in telemetry; - /// if telemetry shouldn't include raw inputs and outputs. - /// The default value is . + /// The value is ignored. The default value is . /// /// - /// By default, telemetry includes metadata but not raw inputs and outputs, - /// such as message content and executor data. + /// Workflow payload attributes are no longer emitted. This option is deprecated + /// and will be removed in version 1.30.0. Agent and chat-client payload capture settings are unaffected. /// + [Obsolete("Workflow payload attributes are no longer emitted. This option has no effect and will be removed in version 1.30.0.")] public bool EnableSensitiveData { get; set; } /// diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows/OpenTelemetryWorkflowBuilderExtensions.cs b/dotnet/src/Microsoft.Agents.AI.Workflows/OpenTelemetryWorkflowBuilderExtensions.cs index ffa0f0362d7..a39dcba2d3d 100644 --- a/dotnet/src/Microsoft.Agents.AI.Workflows/OpenTelemetryWorkflowBuilderExtensions.cs +++ b/dotnet/src/Microsoft.Agents.AI.Workflows/OpenTelemetryWorkflowBuilderExtensions.cs @@ -18,7 +18,7 @@ public static class OpenTelemetryWorkflowBuilderExtensions /// The to which OpenTelemetry support will be added. /// /// An optional callback that provides additional configuration of the instance. - /// This allows for fine-tuning telemetry behavior such as enabling sensitive data collection. + /// This allows for fine-tuning telemetry behavior such as disabling individual activity types. /// /// /// An optional to use for telemetry. If provided, this activity source will be used @@ -46,7 +46,7 @@ public static class OpenTelemetryWorkflowBuilderExtensions /// /// var workflow = new WorkflowBuilder(startExecutor) /// .AddEdge(executor1, executor2) - /// .WithOpenTelemetry(cfg => cfg.EnableSensitiveData = true) + /// .WithOpenTelemetry() /// .Build(); /// /// diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/DeclarativeWorkflowOptionsTest.cs b/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/DeclarativeWorkflowOptionsTest.cs index e032052238a..70236fbbe19 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/DeclarativeWorkflowOptionsTest.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/DeclarativeWorkflowOptionsTest.cs @@ -93,7 +93,7 @@ public void ConfigureTelemetry_CanBeSet() ConfigureTelemetry = opt => { callbackInvoked = true; - opt.EnableSensitiveData = true; + opt.DisableEdgeGroupProcess = true; } }; @@ -102,7 +102,7 @@ public void ConfigureTelemetry_CanBeSet() WorkflowTelemetryOptions telemetryOptions = new(); options.ConfigureTelemetry(telemetryOptions); Assert.True(callbackInvoked); - Assert.True(telemetryOptions.EnableSensitiveData); + Assert.True(telemetryOptions.DisableEdgeGroupProcess); } [Fact] @@ -201,7 +201,7 @@ public async Task BuildWorkflow_WithConfigureTelemetry_AppliesConfigurationAsync ConfigureTelemetry = opt => { configureInvoked = true; - opt.EnableSensitiveData = true; + opt.DisableEdgeGroupProcess = true; }, LoggerFactory = NullLoggerFactory.Instance }; @@ -222,6 +222,7 @@ public async Task BuildWorkflow_WithConfigureTelemetry_AppliesConfigurationAsync Assert.NotEmpty(capturedActivities); Assert.Contains(capturedActivities, a => a.OperationName.StartsWith(WorkflowBuildActivityName, StringComparison.Ordinal)); Assert.Contains(capturedActivities, a => a.OperationName.StartsWith(WorkflowRunActivityName, StringComparison.Ordinal)); + Assert.DoesNotContain(capturedActivities, a => a.OperationName.StartsWith("edge_group.process", StringComparison.Ordinal)); } [Fact] diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/ObservabilityTests.cs b/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/ObservabilityTests.cs index 308ab5ba1f6..b7594fdf6d8 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/ObservabilityTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/ObservabilityTests.cs @@ -4,7 +4,6 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; -using System.IO; using System.Linq; using System.Threading.Tasks; using Microsoft.Agents.AI.Workflows.InProc; @@ -554,8 +553,10 @@ private static Workflow CreateWorkflowWithDisabledMessages() return builder.WithOpenTelemetry(configure: opts => opts.DisableMessageSend = true).Build(); } - [Fact] - public async Task EnableSensitiveData_LogsExecutorInputAndOutputAsync() + [Theory] + [InlineData(false)] + [InlineData(true)] + public async Task EnableSensitiveData_DoesNotLogExecutorInputAndOutputAsync(bool enableSensitiveData) { // Arrange using var testActivity = new Activity("ObservabilityTest").Start(); @@ -566,38 +567,9 @@ public async Task EnableSensitiveData_LogsExecutorInputAndOutputAsync() // Act WorkflowBuilder builder = new(uppercase); builder.WithOutputFrom(uppercase); - var workflow = builder.WithOpenTelemetry(configure: opts => opts.EnableSensitiveData = true).Build(); - - Run run = await InProcessExecution.Default.RunAsync(workflow, "hello"); - await run.DisposeAsync(); - - // Assert - var capturedActivities = this._capturedActivities.Where(a => a.RootId == testActivity.RootId).ToList(); - var executorActivity = capturedActivities.FirstOrDefault( - a => a.OperationName.StartsWith(ActivityNames.ExecutorProcess, StringComparison.Ordinal)); - - Assert.NotNull(executorActivity); - - var tags = executorActivity!.Tags.ToDictionary(t => t.Key, t => t.Value); - Assert.Contains(Tags.ExecutorInput, tags); - Assert.Contains(Tags.ExecutorOutput, tags); - Assert.Contains("hello", tags[Tags.ExecutorInput]); - Assert.Contains("HELLO", tags[Tags.ExecutorOutput]); - } - - [Fact] - public async Task EnableSensitiveData_Disabled_DoesNotLogInputOutputAsync() - { - // Arrange - using var testActivity = new Activity("ObservabilityTest").Start(); - - Func uppercaseFunc = s => s.ToUpperInvariant(); - var uppercase = uppercaseFunc.BindAsExecutor("UppercaseExecutor"); - - // Act - EnableSensitiveData is false by default - WorkflowBuilder builder = new(uppercase); - builder.WithOutputFrom(uppercase); - var workflow = builder.WithOpenTelemetry().Build(); +#pragma warning disable CS0618 // Verify compatibility with the deprecated option. + var workflow = builder.WithOpenTelemetry(configure: opts => opts.EnableSensitiveData = enableSensitiveData).Build(); +#pragma warning restore CS0618 Run run = await InProcessExecution.Default.RunAsync(workflow, "hello"); await run.DisposeAsync(); @@ -609,13 +581,18 @@ public async Task EnableSensitiveData_Disabled_DoesNotLogInputOutputAsync() Assert.NotNull(executorActivity); - var tags = executorActivity!.Tags.ToDictionary(t => t.Key, t => t.Value); - Assert.DoesNotContain(Tags.ExecutorInput, tags); - Assert.DoesNotContain(Tags.ExecutorOutput, tags); + Assert.Equal("UppercaseExecutor", executorActivity.GetTagItem(Tags.ExecutorId)); + Assert.NotNull(executorActivity.GetTagItem(Tags.ExecutorType)); + Assert.NotNull(executorActivity.GetTagItem(Tags.MessageType)); + Assert.All(capturedActivities, activity => + Assert.DoesNotContain(activity.TagObjects, tag => tag.Key is "executor.input" or "executor.output")); + Assert.Equal("HELLO", Assert.Single(run.OutgoingEvents.OfType()).Data); } - [Fact] - public async Task EnableSensitiveData_LogsMessageSendContentAsync() + [Theory] + [InlineData(false)] + [InlineData(true)] + public async Task EnableSensitiveData_DoesNotLogMessageContentAsync(bool enableSensitiveData) { // Arrange using var testActivity = new Activity("ObservabilityTest").Start(); @@ -629,53 +606,22 @@ public async Task EnableSensitiveData_LogsMessageSendContentAsync() // Act WorkflowBuilder builder = new(uppercase); builder.AddEdge(uppercase, reverse).WithOutputFrom(reverse); - var workflow = builder.WithOpenTelemetry(configure: opts => opts.EnableSensitiveData = true).Build(); - - Run run = await InProcessExecution.Default.RunAsync(workflow, "hello"); - await run.DisposeAsync(); - - // Assert - var capturedActivities = this._capturedActivities.Where(a => a.RootId == testActivity.RootId).ToList(); - var messageSendActivity = capturedActivities.FirstOrDefault( - a => a.OperationName.StartsWith(ActivityNames.MessageSend, StringComparison.Ordinal)); - - Assert.NotNull(messageSendActivity); - - var tags = messageSendActivity!.Tags.ToDictionary(t => t.Key, t => t.Value); - Assert.Contains(Tags.MessageContent, tags); - Assert.Contains(Tags.MessageSourceId, tags); - } - - [Fact] - public async Task EnableSensitiveData_Disabled_DoesNotLogMessageContentAsync() - { - // Arrange - using var testActivity = new Activity("ObservabilityTest").Start(); - - Func uppercaseFunc = s => s.ToUpperInvariant(); - var uppercase = uppercaseFunc.BindAsExecutor("UppercaseExecutor"); - - Func reverseFunc = s => new string(s.Reverse().ToArray()); - var reverse = reverseFunc.BindAsExecutor("ReverseTextExecutor"); - - // Act - EnableSensitiveData is false by default - WorkflowBuilder builder = new(uppercase); - builder.AddEdge(uppercase, reverse).WithOutputFrom(reverse); - var workflow = builder.WithOpenTelemetry().Build(); +#pragma warning disable CS0618 // Verify compatibility with the deprecated option. + var workflow = builder.WithOpenTelemetry(configure: opts => opts.EnableSensitiveData = enableSensitiveData).Build(); +#pragma warning restore CS0618 Run run = await InProcessExecution.Default.RunAsync(workflow, "hello"); await run.DisposeAsync(); // Assert var capturedActivities = this._capturedActivities.Where(a => a.RootId == testActivity.RootId).ToList(); - var messageSendActivity = capturedActivities.FirstOrDefault( - a => a.OperationName.StartsWith(ActivityNames.MessageSend, StringComparison.Ordinal)); - - Assert.NotNull(messageSendActivity); - - var tags = messageSendActivity!.Tags.ToDictionary(t => t.Key, t => t.Value); - Assert.DoesNotContain(Tags.MessageContent, tags); - Assert.Contains(Tags.MessageSourceId, tags); + var messageSendActivities = capturedActivities.Where( + a => a.OperationName.StartsWith(ActivityNames.MessageSend, StringComparison.Ordinal)).ToList(); + Assert.NotEmpty(messageSendActivities); + Assert.All(messageSendActivities, activity => Assert.NotNull(activity.GetTagItem(Tags.MessageSourceId))); + Assert.All(capturedActivities, activity => + Assert.DoesNotContain(activity.TagObjects, tag => tag.Key == "message.content")); + Assert.Equal("OLLEH", Assert.Single(run.OutgoingEvents.OfType()).Data); } [Fact] @@ -685,8 +631,6 @@ public async Task EnableSensitiveData_UnserializableMessage_DoesNotFailWorkflowA const string SenderId = "UnserializableMessageSender"; const string ReceiverId = "UnserializableMessageReceiver"; const string ExpectedOutput = "done"; - string expectedFallback = $"[Unserializable: {typeof(ChatMessage).FullName}]"; - using var testActivity = new Activity("ObservabilityTest").Start(); var sender = new UnserializableMessageSender(SenderId, ReceiverId); @@ -700,7 +644,9 @@ public async Task EnableSensitiveData_UnserializableMessage_DoesNotFailWorkflowA WorkflowBuilder builder = new(sender); builder.AddEdge(sender, receiver).WithOutputFrom(receiver); +#pragma warning disable CS0618 // Verify compatibility with the deprecated option. Workflow workflow = builder.WithOpenTelemetry(configure: opts => opts.EnableSensitiveData = true).Build(); +#pragma warning restore CS0618 // Act Run run = await InProcessExecution.Default.RunAsync(workflow, "start"); @@ -715,75 +661,10 @@ public async Task EnableSensitiveData_UnserializableMessage_DoesNotFailWorkflowA Assert.IsType(Assert.Single(delivered.Contents)); List capturedActivities = this._capturedActivities.Where(a => a.RootId == testActivity.RootId).ToList(); - Assert.Contains( - capturedActivities, - activity => activity.OperationName.StartsWith(ActivityNames.MessageSend, StringComparison.Ordinal) - && Equals(expectedFallback, activity.GetTagItem(Tags.MessageContent))); - - Assert.Contains( - capturedActivities, - activity => activity.OperationName.StartsWith(ActivityNames.ExecutorProcess, StringComparison.Ordinal) - && Equals(expectedFallback, activity.GetTagItem(Tags.ExecutorInput))); - } - - [Fact] - public void EnableSensitiveData_UnserializableExecutorInputAndOutput_UsesFallback() - { - // Arrange - string expectedFallback = $"[Unserializable: {typeof(ChatMessage).FullName}]"; - ChatMessage message = CreateUnserializableMessage(); - WorkflowTelemetryContext context = new(new WorkflowTelemetryOptions { EnableSensitiveData = true }); - - // Act - using Activity? activity = context.StartExecutorProcessActivity( - "TestExecutor", - typeof(ObservabilityTests).FullName, - typeof(ChatMessage).FullName!, - message); - context.SetExecutorOutput(activity, message); - - // Assert - Assert.NotNull(activity); - Assert.Equal(expectedFallback, activity!.GetTagItem(Tags.ExecutorInput)); - Assert.Equal(expectedFallback, activity.GetTagItem(Tags.ExecutorOutput)); - } - - [Fact] - public void EnableSensitiveData_SerializationThrowsInvalidOperation_UsesFallback() - { - // Arrange - // Reflection-disabled (Native AOT) apps surface serialization failures as InvalidOperationException, - // which System.Text.Json does not wrap. A throwing property getter reproduces that escape path. - string expectedFallback = $"[Unserializable: {typeof(ThrowingMessage).FullName}]"; - WorkflowTelemetryContext context = new(new WorkflowTelemetryOptions { EnableSensitiveData = true }); - - // Act - using Activity? activity = context.StartMessageSendActivity("source", "target", new ThrowingMessage()); - - // Assert - Assert.NotNull(activity); - Assert.Equal(expectedFallback, activity!.GetTagItem(Tags.MessageContent)); - } - - [Theory] - [InlineData(typeof(ArgumentException))] - [InlineData(typeof(IOException))] - [InlineData(typeof(OperationCanceledException))] - [InlineData(typeof(TimeoutException))] - public void EnableSensitiveData_SerializationThrowsAnyException_UsesFallback(Type exceptionType) - { - // Arrange - // System.Text.Json does not wrap property-getter exceptions, so serialization can surface any - // exception type. Telemetry must fall back rather than fail the workflow for all of them. - string expectedFallback = $"[Unserializable: {typeof(ThrowingMessage).FullName}]"; - WorkflowTelemetryContext context = new(new WorkflowTelemetryOptions { EnableSensitiveData = true }); - - // Act - using Activity? activity = context.StartMessageSendActivity("source", "target", new ThrowingMessage(exceptionType)); - - // Assert - Assert.NotNull(activity); - Assert.Equal(expectedFallback, activity!.GetTagItem(Tags.MessageContent)); + Assert.Contains(capturedActivities, activity => activity.OperationName.StartsWith(ActivityNames.MessageSend, StringComparison.Ordinal)); + Assert.Contains(capturedActivities, activity => activity.OperationName.StartsWith(ActivityNames.ExecutorProcess, StringComparison.Ordinal)); + Assert.All(capturedActivities, activity => + Assert.DoesNotContain(activity.TagObjects, tag => tag.Key is "executor.input" or "executor.output" or "message.content")); } private static ChatMessage CreateUnserializableMessage() => @@ -802,12 +683,4 @@ protected override ProtocolBuilder ConfigureProtocol(ProtocolBuilder protocolBui private sealed class UnregisteredAIContent : AIContent; - private sealed class ThrowingMessage(Type exceptionType) - { - public ThrowingMessage() : this(typeof(InvalidOperationException)) - { - } - - public string Value => throw (Exception)Activator.CreateInstance(exceptionType, "serialization failed")!; - } } diff --git a/skills/agent-framework-builder-dotnet/references/observability.md b/skills/agent-framework-builder-dotnet/references/observability.md index 5769ef4897c..c0838b08943 100644 --- a/skills/agent-framework-builder-dotnet/references/observability.md +++ b/skills/agent-framework-builder-dotnet/references/observability.md @@ -15,6 +15,9 @@ runtime evidence; it does not determine whether output is correct. a generic host. - Keep sensitive payload capture (`EnableSensitiveData`) disabled unless the application explicitly accepts the exposure of prompts, responses, and tool arguments. +- Workflow spans no longer emit `executor.input`, `executor.output`, or `message.content`. Remove assignments to + `WorkflowTelemetryOptions.EnableSensitiveData`: it is obsolete, has no effect, and will be removed in version + 1.30.0. Agent and chat-client sensitive-data capture settings are unchanged. - Name workflows with `WorkflowBuilder.WithName(...)`. Workflow build and invocation activities record this name as `gen_ai.workflow.name` (replacing `workflow.name`); the attribute is omitted when no meaningful name is configured. - Workflow invocation activities are named `invoke_workflow {gen_ai.workflow.name}`, or `invoke_workflow` when no