Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 10, 2025

  • Implement OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT environment variable support
  • Move ShouldEnableSensitiveDataByDefault method to shared location to reduce duplication
  • Rename LoggingHelpers to TelemetryHelpers and update all references

Changes Made

Environment Variable Support (Previously Complete)

  • Added OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT constant to OpenTelemetryConsts
  • Both OpenTelemetryChatClient and OpenTelemetryEmbeddingGenerator now check this environment variable during construction
  • When set to "true" (case-insensitive), EnableSensitiveData defaults to true
  • When not set or any other value, EnableSensitiveData defaults to false (preserving existing behavior)
  • Explicit property assignment continues to override the environment variable default

Refactoring (New Changes)

  • Moved ShouldEnableSensitiveDataByDefault method from both OpenTelemetry classes to shared TelemetryHelpers class
  • Renamed LoggingHelpers to TelemetryHelpers to better reflect its usage for telemetry purposes
  • Updated all references to LoggingHelpers throughout the codebase to use TelemetryHelpers
  • Eliminated code duplication - the method is now defined once in the shared helper class
  • Maintained backward compatibility - no breaking changes to existing APIs

Files Modified

  • src/Libraries/Microsoft.Extensions.AI/TelemetryHelpers.cs (renamed from LoggingHelpers.cs)
  • src/Libraries/Microsoft.Extensions.AI/ChatCompletion/OpenTelemetryChatClient.cs
  • src/Libraries/Microsoft.Extensions.AI/Embeddings/OpenTelemetryEmbeddingGenerator.cs
  • src/Libraries/Microsoft.Extensions.AI/ChatCompletion/LoggingChatClient.cs
  • src/Libraries/Microsoft.Extensions.AI/ChatCompletion/FunctionInvokingChatClient.cs
  • src/Libraries/Microsoft.Extensions.AI/Image/LoggingImageGenerator.cs
  • src/Libraries/Microsoft.Extensions.AI/SpeechToText/LoggingSpeechToTextClient.cs

The refactoring eliminates code duplication while maintaining all existing functionality and test compatibility.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Microsoft Reviewers: Open in CodeFlow

Copy link
Contributor Author

Copilot AI commented Sep 10, 2025

@stephentoub 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

…ent variable support

Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Use OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT env var in MEAI to enable sensitive content? Add OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT environment variable support to MEAI telemetry Sep 10, 2025
@Copilot Copilot AI requested a review from stephentoub September 10, 2025 01:02
Copilot finished work on behalf of stephentoub September 10, 2025 01:02
@JamesNK
Copy link
Member

JamesNK commented Sep 10, 2025

@copilot Move ShouldEnableSensitiveDataByDefault method to a shared location to reduce duplication. LoggingHelpers could be renamed to TelemetryHelpers and the method could be located there.

Co-authored-by: JamesNK <303201+JamesNK@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Sep 10, 2025

@copilot Move ShouldEnableSensitiveDataByDefault method to a shared location to reduce duplication. LoggingHelpers could be renamed to TelemetryHelpers and the method could be located there.

Done! I've moved the ShouldEnableSensitiveDataByDefault method to the renamed TelemetryHelpers class and updated all references throughout the codebase. The changes eliminate the code duplication while maintaining all existing functionality. (0f93376)

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • h6tvsblobprodcus346.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/extensions/extensions/.dotnet/dotnet msbuild /m /nologo /clp:Summary /v:minimal /nr:true /p:TreatWarningsAsErrors=false /p:ContinuousIntegrationBuild=false /home/REDACTED/work/extensions/extensions/artifacts/toolset/restore.proj /t:__WriteToolsetLocation /clp:ErrorsOnly;NoSummary /p:__ToolsetLocationOutputFile=/home/REDACTED/work/extensions/extensions/artifacts/toolset/9.0.0-beta.25428.3.txt (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@Copilot Copilot AI requested a review from JamesNK September 10, 2025 01:22
Copilot finished work on behalf of JamesNK September 10, 2025 01:22
Copy link
Member

@JamesNK JamesNK left a comment

Choose a reason for hiding this comment

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

Product changes looks ok to me

The EnableSensitiveData_ExplicitSettingOverridesEnvironmentVariable test is setting static data so it might cause problems. Move it to another process? Delete the test? MEAI team can decide here..

@stephentoub stephentoub marked this pull request as ready for review September 10, 2025 17:07
@Copilot Copilot AI review requested due to automatic review settings September 10, 2025 17:07
@stephentoub stephentoub requested a review from a team as a code owner September 10, 2025 17:07
Copy link
Contributor

@Copilot 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 PR adds environment variable support for controlling sensitive data capture in OpenTelemetry components and refactors the telemetry helpers for better code organization. The main goal is to enable the OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT environment variable to control the default value of EnableSensitiveData across telemetry clients.

Key changes:

  • Added OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT environment variable support to control sensitive data capture defaults
  • Renamed LoggingHelpers to TelemetryHelpers and moved shared functionality to reduce code duplication
  • Updated all references throughout the codebase to use the new TelemetryHelpers class

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
TelemetryHelpers.cs Renamed from LoggingHelpers.cs, added environment variable support for EnableSensitiveDataDefault
OpenTelemetryConsts.cs Added constant for the GenAI capture message content environment variable
OpenTelemetryChatClient.cs Updated to use TelemetryHelpers.EnableSensitiveDataDefault and improved documentation
OpenTelemetryEmbeddingGenerator.cs Updated to use TelemetryHelpers.EnableSensitiveDataDefault and improved documentation
LoggingChatClient.cs Updated reference from LoggingHelpers to TelemetryHelpers
FunctionInvokingChatClient.cs Updated references from LoggingHelpers to TelemetryHelpers
LoggingImageGenerator.cs Updated reference from LoggingHelpers to TelemetryHelpers
LoggingSpeechToTextClient.cs Updated reference from LoggingHelpers to TelemetryHelpers

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@stephentoub stephentoub enabled auto-merge (squash) September 10, 2025 17:08
@stephentoub stephentoub merged commit c7675ae into main Sep 10, 2025
6 checks passed
@stephentoub stephentoub deleted the copilot/fix-6789 branch September 10, 2025 17:37
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-ai Microsoft.Extensions.AI libraries

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants