From 7e0c01bfbeee399574925e8cd9f67d74483aafde Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Wed, 3 Apr 2024 22:50:02 +0800 Subject: [PATCH] Update OpenTelemetry packages to 1.8.0 (#3351) * Update OpenTelemetry packages to 1.8.0 * Update template versions --- Directory.Packages.props | 10 +++++----- playground/AWS/AWS.ServiceDefaults/Extensions.cs | 12 ++---------- playground/Playground.ServiceDefaults/Extensions.cs | 12 ++---------- playground/TestShop/ServiceDefaults/Extensions.cs | 12 ++---------- .../orleans/OrleansServiceDefaults/Extensions.cs | 12 ++---------- playground/seq/Seq.ServiceDefaults/Extensions.cs | 12 ++---------- src/Aspire.Hosting/OtlpConfigurationExtensions.cs | 8 ++++++-- .../ProjectResourceBuilderExtensions.cs | 5 +++++ .../AspireApplication.1.ServiceDefaults.csproj | 4 ++-- .../Extensions.cs | 12 ++---------- .../Aspire.ServiceDefaults1.csproj | 4 ++-- .../templates/aspire-servicedefaults/Extensions.cs | 12 ++---------- ...AspireStarterApplication.1.ServiceDefaults.csproj | 4 ++-- .../Extensions.cs | 12 ++---------- .../Aspire.Hosting.Tests/ManifestGenerationTests.cs | 7 ++++++- tests/Aspire.Hosting.Tests/ProjectResourceTests.cs | 10 ++++++++-- tests/Aspire.Hosting.Tests/WithEndpointTests.cs | 3 ++- .../TestingAppHost1.ServiceDefaults/Extensions.cs | 12 ++---------- 18 files changed, 56 insertions(+), 107 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index e9e11cab75..7bba00a353 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -103,11 +103,11 @@ - - - - - + + + + + diff --git a/playground/AWS/AWS.ServiceDefaults/Extensions.cs b/playground/AWS/AWS.ServiceDefaults/Extensions.cs index 675692cbc8..25b7e17ef0 100644 --- a/playground/AWS/AWS.ServiceDefaults/Extensions.cs +++ b/playground/AWS/AWS.ServiceDefaults/Extensions.cs @@ -6,7 +6,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Diagnostics.HealthChecks; using Microsoft.Extensions.Logging; -using OpenTelemetry.Logs; +using OpenTelemetry; using OpenTelemetry.Metrics; using OpenTelemetry.Trace; @@ -57,12 +57,6 @@ public static IHostApplicationBuilder ConfigureOpenTelemetry(this IHostApplicati }) .WithTracing(tracing => { - if (builder.Environment.IsDevelopment()) - { - // We want to view all traces in development - tracing.SetSampler(new AlwaysOnSampler()); - } - tracing.AddAspNetCoreInstrumentation() // Uncomment the following line to enable gRPC instrumentation (requires the OpenTelemetry.Instrumentation.GrpcNetClient package) //.AddGrpcClientInstrumentation() @@ -82,9 +76,7 @@ private static IHostApplicationBuilder AddOpenTelemetryExporters(this IHostAppli if (useOtlpExporter) { - builder.Services.Configure(logging => logging.AddOtlpExporter()); - builder.Services.ConfigureOpenTelemetryMeterProvider(metrics => metrics.AddOtlpExporter()); - builder.Services.ConfigureOpenTelemetryTracerProvider(tracing => tracing.AddOtlpExporter()); + builder.Services.AddOpenTelemetry().UseOtlpExporter(); } // Uncomment the following lines to enable the Prometheus exporter (requires the OpenTelemetry.Exporter.Prometheus.AspNetCore package) diff --git a/playground/Playground.ServiceDefaults/Extensions.cs b/playground/Playground.ServiceDefaults/Extensions.cs index 8a6a27b060..c118fcd00f 100644 --- a/playground/Playground.ServiceDefaults/Extensions.cs +++ b/playground/Playground.ServiceDefaults/Extensions.cs @@ -6,7 +6,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Diagnostics.HealthChecks; using Microsoft.Extensions.Logging; -using OpenTelemetry.Logs; +using OpenTelemetry; using OpenTelemetry.Metrics; using OpenTelemetry.Trace; @@ -57,12 +57,6 @@ public static IHostApplicationBuilder ConfigureOpenTelemetry(this IHostApplicati }) .WithTracing(tracing => { - if (builder.Environment.IsDevelopment()) - { - // We want to view all traces in development - tracing.SetSampler(new AlwaysOnSampler()); - } - tracing.AddAspNetCoreInstrumentation() // Uncomment the following line to enable gRPC instrumentation (requires the OpenTelemetry.Instrumentation.GrpcNetClient package) //.AddGrpcClientInstrumentation() @@ -80,9 +74,7 @@ private static IHostApplicationBuilder AddOpenTelemetryExporters(this IHostAppli if (useOtlpExporter) { - builder.Services.Configure(logging => logging.AddOtlpExporter()); - builder.Services.ConfigureOpenTelemetryMeterProvider(metrics => metrics.AddOtlpExporter()); - builder.Services.ConfigureOpenTelemetryTracerProvider(tracing => tracing.AddOtlpExporter()); + builder.Services.AddOpenTelemetry().UseOtlpExporter(); } // Uncomment the following lines to enable the Prometheus exporter (requires the OpenTelemetry.Exporter.Prometheus.AspNetCore package) diff --git a/playground/TestShop/ServiceDefaults/Extensions.cs b/playground/TestShop/ServiceDefaults/Extensions.cs index 755a9f7367..ac8baf01c8 100644 --- a/playground/TestShop/ServiceDefaults/Extensions.cs +++ b/playground/TestShop/ServiceDefaults/Extensions.cs @@ -3,7 +3,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Diagnostics.HealthChecks; using Microsoft.Extensions.Logging; -using OpenTelemetry.Logs; +using OpenTelemetry; using OpenTelemetry.Metrics; using OpenTelemetry.Trace; @@ -54,12 +54,6 @@ public static IHostApplicationBuilder ConfigureOpenTelemetry(this IHostApplicati }) .WithTracing(tracing => { - if (builder.Environment.IsDevelopment()) - { - // We want to view all traces in development - tracing.SetSampler(new AlwaysOnSampler()); - } - tracing.AddAspNetCoreInstrumentation() .AddGrpcClientInstrumentation() .AddHttpClientInstrumentation(); @@ -76,9 +70,7 @@ private static IHostApplicationBuilder AddOpenTelemetryExporters(this IHostAppli if (useOtlpExporter) { - builder.Services.Configure(logging => logging.AddOtlpExporter()); - builder.Services.ConfigureOpenTelemetryMeterProvider(metrics => metrics.AddOtlpExporter()); - builder.Services.ConfigureOpenTelemetryTracerProvider(tracing => tracing.AddOtlpExporter()); + builder.Services.AddOpenTelemetry().UseOtlpExporter(); } // Uncomment the following lines to enable the Prometheus exporter (requires the OpenTelemetry.Exporter.Prometheus.AspNetCore package) diff --git a/playground/orleans/OrleansServiceDefaults/Extensions.cs b/playground/orleans/OrleansServiceDefaults/Extensions.cs index 77a97dabc3..dd830a5def 100644 --- a/playground/orleans/OrleansServiceDefaults/Extensions.cs +++ b/playground/orleans/OrleansServiceDefaults/Extensions.cs @@ -3,7 +3,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Diagnostics.HealthChecks; using Microsoft.Extensions.Logging; -using OpenTelemetry.Logs; +using OpenTelemetry; using OpenTelemetry.Metrics; using OpenTelemetry.Trace; @@ -55,12 +55,6 @@ public static IHostApplicationBuilder ConfigureOpenTelemetry(this IHostApplicati }) .WithTracing(tracing => { - if (builder.Environment.IsDevelopment()) - { - // We want to view all traces in development - tracing.SetSampler(new AlwaysOnSampler()); - } - tracing.AddSource("Microsoft.Orleans.Runtime"); tracing.AddSource("Microsoft.Orleans.Application"); @@ -80,9 +74,7 @@ private static IHostApplicationBuilder AddOpenTelemetryExporters(this IHostAppli if (useOtlpExporter) { - builder.Services.Configure(logging => logging.AddOtlpExporter()); - builder.Services.ConfigureOpenTelemetryMeterProvider(metrics => metrics.AddOtlpExporter()); - builder.Services.ConfigureOpenTelemetryTracerProvider(tracing => tracing.AddOtlpExporter()); + builder.Services.AddOpenTelemetry().UseOtlpExporter(); } // Uncomment the following lines to enable the Prometheus exporter (requires the OpenTelemetry.Exporter.Prometheus.AspNetCore package) diff --git a/playground/seq/Seq.ServiceDefaults/Extensions.cs b/playground/seq/Seq.ServiceDefaults/Extensions.cs index 42ff5356ef..3014995ad9 100644 --- a/playground/seq/Seq.ServiceDefaults/Extensions.cs +++ b/playground/seq/Seq.ServiceDefaults/Extensions.cs @@ -7,7 +7,7 @@ using Microsoft.Extensions.Diagnostics.HealthChecks; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; -using OpenTelemetry.Logs; +using OpenTelemetry; using OpenTelemetry.Metrics; using OpenTelemetry.Trace; @@ -58,12 +58,6 @@ public static IHostApplicationBuilder ConfigureOpenTelemetry(this IHostApplicati }) .WithTracing(tracing => { - if (builder.Environment.IsDevelopment()) - { - // We want to view all traces in development - tracing.SetSampler(new AlwaysOnSampler()); - } - tracing.AddSource("MyApp.Source"); tracing.AddAspNetCoreInstrumentation() @@ -83,9 +77,7 @@ private static IHostApplicationBuilder AddOpenTelemetryExporters(this IHostAppli if (useOtlpExporter) { - builder.Services.Configure(logging => logging.AddOtlpExporter()); - builder.Services.ConfigureOpenTelemetryMeterProvider(metrics => metrics.AddOtlpExporter()); - builder.Services.ConfigureOpenTelemetryTracerProvider(tracing => tracing.AddOtlpExporter()); + builder.Services.AddOpenTelemetry().UseOtlpExporter(); } // Uncomment the following lines to enable the Prometheus exporter (requires the OpenTelemetry.Exporter.Prometheus.AspNetCore package) diff --git a/src/Aspire.Hosting/OtlpConfigurationExtensions.cs b/src/Aspire.Hosting/OtlpConfigurationExtensions.cs index 28d7c9118e..dfc35ea259 100644 --- a/src/Aspire.Hosting/OtlpConfigurationExtensions.cs +++ b/src/Aspire.Hosting/OtlpConfigurationExtensions.cs @@ -46,14 +46,18 @@ public static void AddOtlpEnvironment(IResource resource, IConfiguration configu context.EnvironmentVariables["OTEL_EXPORTER_OTLP_HEADERS"] = $"x-otlp-api-key={otlpApiKey}"; } - // Set a small batch schedule delay in development. - // This reduces the delay that OTLP exporter waits to sends telemetry and makes the dashboard telemetry pages responsive. + // Configure OTLP to quickly provide all data with a small delay in development. if (environment.IsDevelopment()) { + // Set a small batch schedule delay in development. + // This reduces the delay that OTLP exporter waits to sends telemetry and makes the dashboard telemetry pages responsive. var value = "1000"; // milliseconds context.EnvironmentVariables["OTEL_BLRP_SCHEDULE_DELAY"] = value; context.EnvironmentVariables["OTEL_BSP_SCHEDULE_DELAY"] = value; context.EnvironmentVariables["OTEL_METRIC_EXPORT_INTERVAL"] = value; + + // Configure trace sampler to send all traces to the dashboard. + context.EnvironmentVariables["OTEL_TRACES_SAMPLER"] = "always_on"; } })); } diff --git a/src/Aspire.Hosting/ProjectResourceBuilderExtensions.cs b/src/Aspire.Hosting/ProjectResourceBuilderExtensions.cs index 605aac5924..bc333328b6 100644 --- a/src/Aspire.Hosting/ProjectResourceBuilderExtensions.cs +++ b/src/Aspire.Hosting/ProjectResourceBuilderExtensions.cs @@ -91,6 +91,11 @@ private static IResourceBuilder WithProjectDefaults(this IResou // implements IDistributedApplicationResourceWithEnvironment. builder.WithEnvironment("OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EXCEPTION_LOG_ATTRIBUTES", "true"); builder.WithEnvironment("OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EVENT_LOG_ATTRIBUTES", "true"); + // .NET SDK has experimental support for retries. Enable with env var. + // https://github.com/open-telemetry/opentelemetry-dotnet/pull/5495 + // Remove once retry feature in opentelemetry-dotnet is enabled by default. + builder.WithEnvironment("OTEL_DOTNET_EXPERIMENTAL_OTLP_RETRY", "in_memory"); + builder.WithOtlpExporter(); builder.ConfigureConsoleLogs(); diff --git a/src/Aspire.ProjectTemplates/templates/aspire-empty/AspireApplication.1.ServiceDefaults/AspireApplication.1.ServiceDefaults.csproj b/src/Aspire.ProjectTemplates/templates/aspire-empty/AspireApplication.1.ServiceDefaults/AspireApplication.1.ServiceDefaults.csproj index f781d72887..e2fb803fe9 100644 --- a/src/Aspire.ProjectTemplates/templates/aspire-empty/AspireApplication.1.ServiceDefaults/AspireApplication.1.ServiceDefaults.csproj +++ b/src/Aspire.ProjectTemplates/templates/aspire-empty/AspireApplication.1.ServiceDefaults/AspireApplication.1.ServiceDefaults.csproj @@ -12,8 +12,8 @@ - - + + diff --git a/src/Aspire.ProjectTemplates/templates/aspire-empty/AspireApplication.1.ServiceDefaults/Extensions.cs b/src/Aspire.ProjectTemplates/templates/aspire-empty/AspireApplication.1.ServiceDefaults/Extensions.cs index cb872a6a26..b6e80000de 100644 --- a/src/Aspire.ProjectTemplates/templates/aspire-empty/AspireApplication.1.ServiceDefaults/Extensions.cs +++ b/src/Aspire.ProjectTemplates/templates/aspire-empty/AspireApplication.1.ServiceDefaults/Extensions.cs @@ -3,7 +3,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Diagnostics.HealthChecks; using Microsoft.Extensions.Logging; -using OpenTelemetry.Logs; +using OpenTelemetry; using OpenTelemetry.Metrics; using OpenTelemetry.Trace; @@ -48,12 +48,6 @@ public static IHostApplicationBuilder ConfigureOpenTelemetry(this IHostApplicati }) .WithTracing(tracing => { - if (builder.Environment.IsDevelopment()) - { - // We want to view all traces in development - tracing.SetSampler(new AlwaysOnSampler()); - } - tracing.AddAspNetCoreInstrumentation() // Uncomment the following line to enable gRPC instrumentation (requires the OpenTelemetry.Instrumentation.GrpcNetClient package) //.AddGrpcClientInstrumentation() @@ -71,9 +65,7 @@ private static IHostApplicationBuilder AddOpenTelemetryExporters(this IHostAppli if (useOtlpExporter) { - builder.Services.Configure(logging => logging.AddOtlpExporter()); - builder.Services.ConfigureOpenTelemetryMeterProvider(metrics => metrics.AddOtlpExporter()); - builder.Services.ConfigureOpenTelemetryTracerProvider(tracing => tracing.AddOtlpExporter()); + builder.Services.AddOpenTelemetry().UseOtlpExporter(); } // Uncomment the following lines to enable the Prometheus exporter (requires the OpenTelemetry.Exporter.Prometheus.AspNetCore package) diff --git a/src/Aspire.ProjectTemplates/templates/aspire-servicedefaults/Aspire.ServiceDefaults1.csproj b/src/Aspire.ProjectTemplates/templates/aspire-servicedefaults/Aspire.ServiceDefaults1.csproj index f781d72887..e2fb803fe9 100644 --- a/src/Aspire.ProjectTemplates/templates/aspire-servicedefaults/Aspire.ServiceDefaults1.csproj +++ b/src/Aspire.ProjectTemplates/templates/aspire-servicedefaults/Aspire.ServiceDefaults1.csproj @@ -12,8 +12,8 @@ - - + + diff --git a/src/Aspire.ProjectTemplates/templates/aspire-servicedefaults/Extensions.cs b/src/Aspire.ProjectTemplates/templates/aspire-servicedefaults/Extensions.cs index c15e1a668b..134217bfdc 100644 --- a/src/Aspire.ProjectTemplates/templates/aspire-servicedefaults/Extensions.cs +++ b/src/Aspire.ProjectTemplates/templates/aspire-servicedefaults/Extensions.cs @@ -4,7 +4,7 @@ using Microsoft.Extensions.Diagnostics.HealthChecks; using Microsoft.Extensions.Logging; using Microsoft.Extensions.ServiceDiscovery; -using OpenTelemetry.Logs; +using OpenTelemetry; using OpenTelemetry.Metrics; using OpenTelemetry.Trace; @@ -55,12 +55,6 @@ public static IHostApplicationBuilder ConfigureOpenTelemetry(this IHostApplicati }) .WithTracing(tracing => { - if (builder.Environment.IsDevelopment()) - { - // We want to view all traces in development - tracing.SetSampler(new AlwaysOnSampler()); - } - tracing.AddAspNetCoreInstrumentation() // Uncomment the following line to enable gRPC instrumentation (requires the OpenTelemetry.Instrumentation.GrpcNetClient package) //.AddGrpcClientInstrumentation() @@ -78,9 +72,7 @@ private static IHostApplicationBuilder AddOpenTelemetryExporters(this IHostAppli if (useOtlpExporter) { - builder.Services.Configure(logging => logging.AddOtlpExporter()); - builder.Services.ConfigureOpenTelemetryMeterProvider(metrics => metrics.AddOtlpExporter()); - builder.Services.ConfigureOpenTelemetryTracerProvider(tracing => tracing.AddOtlpExporter()); + builder.Services.AddOpenTelemetry().UseOtlpExporter(); } // Uncomment the following lines to enable the Prometheus exporter (requires the OpenTelemetry.Exporter.Prometheus.AspNetCore package) diff --git a/src/Aspire.ProjectTemplates/templates/aspire-starter/AspireStarterApplication.1.ServiceDefaults/AspireStarterApplication.1.ServiceDefaults.csproj b/src/Aspire.ProjectTemplates/templates/aspire-starter/AspireStarterApplication.1.ServiceDefaults/AspireStarterApplication.1.ServiceDefaults.csproj index f781d72887..e2fb803fe9 100644 --- a/src/Aspire.ProjectTemplates/templates/aspire-starter/AspireStarterApplication.1.ServiceDefaults/AspireStarterApplication.1.ServiceDefaults.csproj +++ b/src/Aspire.ProjectTemplates/templates/aspire-starter/AspireStarterApplication.1.ServiceDefaults/AspireStarterApplication.1.ServiceDefaults.csproj @@ -12,8 +12,8 @@ - - + + diff --git a/src/Aspire.ProjectTemplates/templates/aspire-starter/AspireStarterApplication.1.ServiceDefaults/Extensions.cs b/src/Aspire.ProjectTemplates/templates/aspire-starter/AspireStarterApplication.1.ServiceDefaults/Extensions.cs index 59af9c15ad..877f870b74 100644 --- a/src/Aspire.ProjectTemplates/templates/aspire-starter/AspireStarterApplication.1.ServiceDefaults/Extensions.cs +++ b/src/Aspire.ProjectTemplates/templates/aspire-starter/AspireStarterApplication.1.ServiceDefaults/Extensions.cs @@ -3,7 +3,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Diagnostics.HealthChecks; using Microsoft.Extensions.Logging; -using OpenTelemetry.Logs; +using OpenTelemetry; using OpenTelemetry.Metrics; using OpenTelemetry.Trace; @@ -48,12 +48,6 @@ public static IHostApplicationBuilder ConfigureOpenTelemetry(this IHostApplicati }) .WithTracing(tracing => { - if (builder.Environment.IsDevelopment()) - { - // We want to view all traces in development - tracing.SetSampler(new AlwaysOnSampler()); - } - tracing.AddAspNetCoreInstrumentation() // Uncomment the following line to enable gRPC instrumentation (requires the OpenTelemetry.Instrumentation.GrpcNetClient package) //.AddGrpcClientInstrumentation() @@ -71,9 +65,7 @@ private static IHostApplicationBuilder AddOpenTelemetryExporters(this IHostAppli if (useOtlpExporter) { - builder.Services.Configure(logging => logging.AddOtlpExporter()); - builder.Services.ConfigureOpenTelemetryMeterProvider(metrics => metrics.AddOtlpExporter()); - builder.Services.ConfigureOpenTelemetryTracerProvider(tracing => tracing.AddOtlpExporter()); + builder.Services.AddOpenTelemetry().UseOtlpExporter(); } // Uncomment the following lines to enable the Prometheus exporter (requires the OpenTelemetry.Exporter.Prometheus.AspNetCore package) diff --git a/tests/Aspire.Hosting.Tests/ManifestGenerationTests.cs b/tests/Aspire.Hosting.Tests/ManifestGenerationTests.cs index 154b6db07c..0262e09f62 100644 --- a/tests/Aspire.Hosting.Tests/ManifestGenerationTests.cs +++ b/tests/Aspire.Hosting.Tests/ManifestGenerationTests.cs @@ -539,6 +539,7 @@ public void VerifyTestProgramFullManifest() "env": { "OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EXCEPTION_LOG_ATTRIBUTES": "true", "OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EVENT_LOG_ATTRIBUTES": "true", + "OTEL_DOTNET_EXPERIMENTAL_OTLP_RETRY": "in_memory", "ASPNETCORE_FORWARDEDHEADERS_ENABLED": "true" }, "bindings": { @@ -560,6 +561,7 @@ public void VerifyTestProgramFullManifest() "env": { "OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EXCEPTION_LOG_ATTRIBUTES": "true", "OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EVENT_LOG_ATTRIBUTES": "true", + "OTEL_DOTNET_EXPERIMENTAL_OTLP_RETRY": "in_memory", "ASPNETCORE_FORWARDEDHEADERS_ENABLED": "true" }, "bindings": { @@ -581,6 +583,7 @@ public void VerifyTestProgramFullManifest() "env": { "OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EXCEPTION_LOG_ATTRIBUTES": "true", "OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EVENT_LOG_ATTRIBUTES": "true", + "OTEL_DOTNET_EXPERIMENTAL_OTLP_RETRY": "in_memory", "ASPNETCORE_FORWARDEDHEADERS_ENABLED": "true" }, "bindings": { @@ -601,7 +604,8 @@ public void VerifyTestProgramFullManifest() "path": "testproject/TestProject.WorkerA/TestProject.WorkerA.csproj", "env": { "OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EXCEPTION_LOG_ATTRIBUTES": "true", - "OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EVENT_LOG_ATTRIBUTES": "true" + "OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EVENT_LOG_ATTRIBUTES": "true", + "OTEL_DOTNET_EXPERIMENTAL_OTLP_RETRY": "in_memory" } }, "integrationservicea": { @@ -610,6 +614,7 @@ public void VerifyTestProgramFullManifest() "env": { "OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EXCEPTION_LOG_ATTRIBUTES": "true", "OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EVENT_LOG_ATTRIBUTES": "true", + "OTEL_DOTNET_EXPERIMENTAL_OTLP_RETRY": "in_memory", "ASPNETCORE_FORWARDEDHEADERS_ENABLED": "true", "SKIP_RESOURCES": "", "ConnectionStrings__tempdb": "{tempdb.connectionString}", diff --git a/tests/Aspire.Hosting.Tests/ProjectResourceTests.cs b/tests/Aspire.Hosting.Tests/ProjectResourceTests.cs index 29d0e2ba3c..6ce5529116 100644 --- a/tests/Aspire.Hosting.Tests/ProjectResourceTests.cs +++ b/tests/Aspire.Hosting.Tests/ProjectResourceTests.cs @@ -26,7 +26,7 @@ public async Task AddProjectAddsEnvironmentVariablesAndServiceMetadata() var resource = Assert.Single(projectResources); Assert.Equal("projectName", resource.Name); - Assert.Equal(7, resource.Annotations.Count); + Assert.Equal(8, resource.Annotations.Count); var serviceMetadata = Assert.Single(resource.Annotations.OfType()); Assert.IsType(serviceMetadata); @@ -45,6 +45,11 @@ public async Task AddProjectAddsEnvironmentVariablesAndServiceMetadata() Assert.Equal("true", env.Value); }, env => + { + Assert.Equal("OTEL_DOTNET_EXPERIMENTAL_OTLP_RETRY", env.Key); + Assert.Equal("in_memory", env.Value); + }, + env => { Assert.Equal("OTEL_EXPORTER_OTLP_ENDPOINT", env.Key); Assert.Equal("http://localhost:18889", env.Value); @@ -262,7 +267,8 @@ public async Task VerifyManifest(bool disableForwardedHeaders) "path": "another-path", "env": { "OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EXCEPTION_LOG_ATTRIBUTES": "true", - "OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EVENT_LOG_ATTRIBUTES": "true"{{fordwardedHeadersEnvVar}} + "OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EVENT_LOG_ATTRIBUTES": "true", + "OTEL_DOTNET_EXPERIMENTAL_OTLP_RETRY": "in_memory"{{fordwardedHeadersEnvVar}} }, "bindings": { "http": { diff --git a/tests/Aspire.Hosting.Tests/WithEndpointTests.cs b/tests/Aspire.Hosting.Tests/WithEndpointTests.cs index 4dac7720a6..e2e24afe41 100644 --- a/tests/Aspire.Hosting.Tests/WithEndpointTests.cs +++ b/tests/Aspire.Hosting.Tests/WithEndpointTests.cs @@ -369,7 +369,8 @@ public async Task VerifyManifestProjectWithHttpEndpointDoesNotAllocatePort() "path": "projectpath", "env": { "OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EXCEPTION_LOG_ATTRIBUTES": "true", - "OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EVENT_LOG_ATTRIBUTES": "true" + "OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EVENT_LOG_ATTRIBUTES": "true", + "OTEL_DOTNET_EXPERIMENTAL_OTLP_RETRY": "in_memory" }, "bindings": { "hp": { diff --git a/tests/TestingAppHost1/TestingAppHost1.ServiceDefaults/Extensions.cs b/tests/TestingAppHost1/TestingAppHost1.ServiceDefaults/Extensions.cs index 9fa1a0e1bb..0b4d0e3899 100644 --- a/tests/TestingAppHost1/TestingAppHost1.ServiceDefaults/Extensions.cs +++ b/tests/TestingAppHost1/TestingAppHost1.ServiceDefaults/Extensions.cs @@ -3,7 +3,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Diagnostics.HealthChecks; using Microsoft.Extensions.Logging; -using OpenTelemetry.Logs; +using OpenTelemetry; using OpenTelemetry.Metrics; using OpenTelemetry.Trace; @@ -54,12 +54,6 @@ public static IHostApplicationBuilder ConfigureOpenTelemetry(this IHostApplicati }) .WithTracing(tracing => { - if (builder.Environment.IsDevelopment()) - { - // We want to view all traces in development - tracing.SetSampler(new AlwaysOnSampler()); - } - tracing.AddAspNetCoreInstrumentation() // Uncomment the following line to enable gRPC instrumentation (requires the OpenTelemetry.Instrumentation.GrpcNetClient package) //.AddGrpcClientInstrumentation() @@ -77,9 +71,7 @@ private static IHostApplicationBuilder AddOpenTelemetryExporters(this IHostAppli if (useOtlpExporter) { - builder.Services.Configure(logging => logging.AddOtlpExporter()); - builder.Services.ConfigureOpenTelemetryMeterProvider(metrics => metrics.AddOtlpExporter()); - builder.Services.ConfigureOpenTelemetryTracerProvider(tracing => tracing.AddOtlpExporter()); + builder.Services.AddOpenTelemetry().UseOtlpExporter(); } // Uncomment the following lines to enable the Prometheus exporter (requires the OpenTelemetry.Exporter.Prometheus.AspNetCore package)