.NET: Propagate EnableSensitiveData to auto-wired inner OpenTelemetryChatClient#6096
Open
Copilot wants to merge 1 commit into
Open
.NET: Propagate EnableSensitiveData to auto-wired inner OpenTelemetryChatClient#6096Copilot wants to merge 1 commit into
Copilot wants to merge 1 commit into
Conversation
…hatClient When _autoWireChatClient=true and the caller sets EnableSensitiveData=true on the outer OpenTelemetryAgent, the auto-wired inner OpenTelemetryChatClient now also has EnableSensitiveData propagated, so the inner chat span correctly captures message content (gen_ai.input.messages / gen_ai.output.messages). Red test added first to reproduce the bug, then the fix applied (green). Fixes #5873 Agent-Logs-Url: https://github.com/microsoft/agent-framework/sessions/fda69dd4-9576-4f3f-b954-514321652ea9 Co-authored-by: rogerbarreto <19890735+rogerbarreto@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
rogerbarreto
May 26, 2026 20:11
View session
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a telemetry configuration propagation bug in the .NET OpenTelemetryAgent auto-wiring path: when the agent is configured with EnableSensitiveData = true, the implicitly-created inner OpenTelemetryChatClient is now configured the same way, ensuring GenAI message-content tags are emitted consistently.
Changes:
- Propagate
OpenTelemetryAgent.EnableSensitiveDatainto the auto-wired innerOpenTelemetryChatClientcreated byGetRunOptionsWithChatClientWiring. - Add a regression theory test covering
EnableSensitiveData× (streaming vs non-streaming) and assertinggen_ai.input.messages/gen_ai.output.messagespresence in the inner chat span.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| dotnet/src/Microsoft.Agents.AI/OpenTelemetryAgent.cs | Forwards EnableSensitiveData to the auto-wired inner OpenTelemetryChatClient via the UseOpenTelemetry(..., configure: ...) callback. |
| dotnet/tests/Microsoft.Agents.AI.UnitTests/OpenTelemetryAgentTests.cs | Adds a regression theory verifying sensitive-data capture tags are present/absent on the inner chat span as expected. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation and Context
When
EnableSensitiveData = trueis set onOpenTelemetryAgentand auto-wiring is active, the innerOpenTelemetryChatClientcreated byGetRunOptionsWithChatClientWiringwas always instantiated with the defaultEnableSensitiveData = false. This caused the inner chat span to silently omitgen_ai.input.messages/gen_ai.output.messageseven when the caller explicitly opted in to sensitive data capture — violating the OpenTelemetry GenAI semantic conventions contract described in the issue.Description
Root cause:
WrapIfNeededwas a zero-parameter static local that calledUseOpenTelemetry(sourceName: sourceName)with noconfigurecallback, soEnableSensitiveDatawas never forwarded to the auto-wired client.Fix (
OpenTelemetryAgent.cs):The value is read once at
GetRunOptionsWithChatClientWiringcall-time and captured in the factory closure, consistent with howsourceNameis already handled. Both theChatClientAgentRunOptionsclone path and the plainAgentRunOptions→ new-options path are updated.Test (
OpenTelemetryAgentTests.cs): AddedAutoWireChatClient_EnableSensitiveData_PropagatedToInnerChatClient_Async— a 4-variant theory (enableSensitiveData × streaming) written red-first to replicate the bug, then green after the fix. Asserts that the inner chat span includes/excludesgen_ai.input.messagesandgen_ai.output.messagesin lock-step with the outer agent'sEnableSensitiveDataflag.Contribution Checklist