Skip to content

Commit 56a471a

Browse files
github-actions[bot]CopilotJamesNK
authored
[release/13.0] Default OpenAISettings.EnableSensitiveTelemetryData to TelemetryHelpers.EnableSensitiveDataDefault (#13017)
* Initial plan * Default OpenAISettings.EnableSensitiveTelemetryData to TelemetryHelpers.EnableSensitiveDataDefault Co-authored-by: JamesNK <303201+JamesNK@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: JamesNK <303201+JamesNK@users.noreply.github.com>
1 parent 42ccc16 commit 56a471a

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed

src/Components/Aspire.OpenAI/Aspire.OpenAI.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
</PropertyGroup>
1414

1515
<ItemGroup>
16+
<Compile Include="..\Common\AITelemetryHelpers.cs" Link="AITelemetryHelpers.cs" />
1617
<Compile Include="..\Common\ConfigurationSchemaAttributes.cs" Link="ConfigurationSchemaAttributes.cs" />
1718
</ItemGroup>
1819

src/Components/Aspire.OpenAI/OpenAISettings.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,16 @@ public sealed class OpenAISettings
4040
/// <value>
4141
/// <see langword="true"/> if potentially sensitive information should be included in telemetry;
4242
/// <see langword="false"/> if telemetry shouldn't include raw inputs and outputs.
43-
/// The default value is <see langword="false"/>.
43+
/// The default value is <see langword="false"/>, unless the <c>OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT</c>
44+
/// environment variable is set to "true" (case-insensitive).
4445
/// </value>
4546
/// <remarks>
4647
/// By default, telemetry includes metadata, such as token counts, but not raw inputs
4748
/// and outputs, such as message content, function call arguments, and function call results.
49+
/// The default value can be overridden by setting the <c>OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT</c>
50+
/// environment variable to "true". Explicitly setting this property will override the environment variable.
4851
/// </remarks>
49-
public bool EnableSensitiveTelemetryData { get; set; }
52+
public bool EnableSensitiveTelemetryData { get; set; } = TelemetryHelpers.EnableSensitiveDataDefault;
5053

5154
internal void ParseConnectionString(string? connectionString)
5255
{

tests/Aspire.OpenAI.Tests/AspireOpenAIExtensionsTests.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,4 +230,46 @@ public void BindsToNamedClientOptions()
230230
Assert.NotNull(options);
231231
Assert.Equal("myproject2", options.ProjectId);
232232
}
233+
234+
[Fact]
235+
public void EnableSensitiveTelemetryData_DefaultsToEnvironmentVariable()
236+
{
237+
var builder = Host.CreateEmptyApplicationBuilder(null);
238+
builder.Configuration.AddInMemoryCollection([
239+
new KeyValuePair<string, string?>("ConnectionStrings:openai", ConnectionString)
240+
]);
241+
242+
OpenAISettings? localSettings = null;
243+
244+
builder.AddOpenAIClient("openai", settings =>
245+
{
246+
localSettings = settings;
247+
});
248+
249+
Assert.NotNull(localSettings);
250+
// The default should be based on TelemetryHelpers.EnableSensitiveDataDefault
251+
// which reads from OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT environment variable
252+
// In test environment without the env var set, it should default to false
253+
Assert.False(localSettings.EnableSensitiveTelemetryData);
254+
}
255+
256+
[Fact]
257+
public void EnableSensitiveTelemetryData_CanBeOverriddenByConfiguration()
258+
{
259+
var builder = Host.CreateEmptyApplicationBuilder(null);
260+
builder.Configuration.AddInMemoryCollection([
261+
new KeyValuePair<string, string?>("ConnectionStrings:openai", ConnectionString),
262+
new KeyValuePair<string, string?>("Aspire:OpenAI:EnableSensitiveTelemetryData", "true")
263+
]);
264+
265+
OpenAISettings? localSettings = null;
266+
267+
builder.AddOpenAIClient("openai", settings =>
268+
{
269+
localSettings = settings;
270+
});
271+
272+
Assert.NotNull(localSettings);
273+
Assert.True(localSettings.EnableSensitiveTelemetryData);
274+
}
233275
}

0 commit comments

Comments
 (0)