From 22fc06c8c92acfd5a1db4beab3f8d820ec0299c3 Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Tue, 25 Jun 2024 11:09:53 +0800 Subject: [PATCH] Use env var --- playground/TestShop/ServiceDefaults/Extensions.cs | 1 - src/Aspire.Hosting/OtlpConfigurationExtensions.cs | 2 ++ tests/Aspire.Hosting.Tests/ProjectResourceTests.cs | 5 +++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/playground/TestShop/ServiceDefaults/Extensions.cs b/playground/TestShop/ServiceDefaults/Extensions.cs index 56ed40561b..ac8baf01c8 100644 --- a/playground/TestShop/ServiceDefaults/Extensions.cs +++ b/playground/TestShop/ServiceDefaults/Extensions.cs @@ -48,7 +48,6 @@ public static IHostApplicationBuilder ConfigureOpenTelemetry(this IHostApplicati builder.Services.AddOpenTelemetry() .WithMetrics(metrics => { - metrics.SetExemplarFilter(ExemplarFilterType.TraceBased); metrics.AddAspNetCoreInstrumentation() .AddHttpClientInstrumentation() .AddRuntimeInstrumentation(); diff --git a/src/Aspire.Hosting/OtlpConfigurationExtensions.cs b/src/Aspire.Hosting/OtlpConfigurationExtensions.cs index 260d222445..d97bc32ed0 100644 --- a/src/Aspire.Hosting/OtlpConfigurationExtensions.cs +++ b/src/Aspire.Hosting/OtlpConfigurationExtensions.cs @@ -76,6 +76,8 @@ public static void AddOtlpEnvironment(IResource resource, IConfiguration configu // Configure trace sampler to send all traces to the dashboard. context.EnvironmentVariables["OTEL_TRACES_SAMPLER"] = "always_on"; + // Configure metrics to include exemplars. + context.EnvironmentVariables["OTEL_METRICS_EXEMPLAR_FILTER"] = "trace_based"; } })); diff --git a/tests/Aspire.Hosting.Tests/ProjectResourceTests.cs b/tests/Aspire.Hosting.Tests/ProjectResourceTests.cs index 3b2300e079..5a3edfc555 100644 --- a/tests/Aspire.Hosting.Tests/ProjectResourceTests.cs +++ b/tests/Aspire.Hosting.Tests/ProjectResourceTests.cs @@ -109,6 +109,11 @@ public async Task AddProjectAddsEnvironmentVariablesAndServiceMetadata() Assert.Equal("always_on", env.Value); }, env => + { + Assert.Equal("OTEL_METRICS_EXEMPLAR_FILTER", env.Key); + Assert.Equal("trace_based", env.Value); + }, + env => { Assert.Equal("DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION", env.Key); Assert.Equal("true", env.Value);