Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Components/Aspire.OpenAI/Aspire.OpenAI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
</PropertyGroup>

<ItemGroup>
<Compile Include="..\Common\AITelemetryHelpers.cs" Link="AITelemetryHelpers.cs" />
<Compile Include="..\Common\ConfigurationSchemaAttributes.cs" Link="ConfigurationSchemaAttributes.cs" />
</ItemGroup>

Expand Down
7 changes: 5 additions & 2 deletions src/Components/Aspire.OpenAI/OpenAISettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,16 @@ public sealed class OpenAISettings
/// <value>
/// <see langword="true"/> if potentially sensitive information should be included in telemetry;
/// <see langword="false"/> if telemetry shouldn't include raw inputs and outputs.
/// The default value is <see langword="false"/>.
/// The default value is <see langword="false"/>, unless the <c>OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT</c>
/// environment variable is set to "true" (case-insensitive).
/// </value>
/// <remarks>
/// By default, telemetry includes metadata, such as token counts, but not raw inputs
/// and outputs, such as message content, function call arguments, and function call results.
/// The default value can be overridden by setting the <c>OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT</c>
/// environment variable to "true". Explicitly setting this property will override the environment variable.
/// </remarks>
public bool EnableSensitiveTelemetryData { get; set; }
public bool EnableSensitiveTelemetryData { get; set; } = TelemetryHelpers.EnableSensitiveDataDefault;

internal void ParseConnectionString(string? connectionString)
{
Expand Down
42 changes: 42 additions & 0 deletions tests/Aspire.OpenAI.Tests/AspireOpenAIExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,46 @@ public void BindsToNamedClientOptions()
Assert.NotNull(options);
Assert.Equal("myproject2", options.ProjectId);
}

[Fact]
public void EnableSensitiveTelemetryData_DefaultsToEnvironmentVariable()
{
var builder = Host.CreateEmptyApplicationBuilder(null);
builder.Configuration.AddInMemoryCollection([
new KeyValuePair<string, string?>("ConnectionStrings:openai", ConnectionString)
]);

OpenAISettings? localSettings = null;

builder.AddOpenAIClient("openai", settings =>
{
localSettings = settings;
});

Assert.NotNull(localSettings);
// The default should be based on TelemetryHelpers.EnableSensitiveDataDefault
// which reads from OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT environment variable
// In test environment without the env var set, it should default to false
Assert.False(localSettings.EnableSensitiveTelemetryData);
}

[Fact]
public void EnableSensitiveTelemetryData_CanBeOverriddenByConfiguration()
{
var builder = Host.CreateEmptyApplicationBuilder(null);
builder.Configuration.AddInMemoryCollection([
new KeyValuePair<string, string?>("ConnectionStrings:openai", ConnectionString),
new KeyValuePair<string, string?>("Aspire:OpenAI:EnableSensitiveTelemetryData", "true")
]);

OpenAISettings? localSettings = null;

builder.AddOpenAIClient("openai", settings =>
{
localSettings = settings;
});

Assert.NotNull(localSettings);
Assert.True(localSettings.EnableSensitiveTelemetryData);
}
}