diff --git a/docs-builder.slnx b/docs-builder.slnx index c747cb81c..6bde14dd7 100644 --- a/docs-builder.slnx +++ b/docs-builder.slnx @@ -28,7 +28,6 @@ - diff --git a/src/Elastic.Documentation.ServiceDefaults/Extensions.cs b/src/Elastic.Documentation.ServiceDefaults/Extensions.cs index 6d415040a..63d479679 100644 --- a/src/Elastic.Documentation.ServiceDefaults/Extensions.cs +++ b/src/Elastic.Documentation.ServiceDefaults/Extensions.cs @@ -25,10 +25,6 @@ public static class Extensions public static TBuilder AddServiceDefaults(this TBuilder builder) where TBuilder : IHostApplicationBuilder { - _ = builder - .ConfigureOpenTelemetry() - .AddDefaultHealthChecks(); - _ = builder.Services .AddServiceDiscovery() .ConfigureHttpClientDefaults(http => @@ -39,7 +35,7 @@ public static TBuilder AddServiceDefaults(this TBuilder builder) where return builder; } - public static TBuilder ConfigureOpenTelemetry(this TBuilder builder) where TBuilder : IHostApplicationBuilder + public static TBuilder AddOpenTelemetryDefaults(this TBuilder builder) where TBuilder : IHostApplicationBuilder { _ = builder.Logging.AddOpenTelemetry(logging => { @@ -108,23 +104,4 @@ public static TBuilder AddDefaultHealthChecks(this TBuilder builder) w return builder; } - - public static WebApplication MapDefaultEndpoints(this WebApplication app) - { - // Adding health checks endpoints to applications in non-development environments has security implications. - // See https://aka.ms/dotnet/aspire/healthchecks for details before enabling these endpoints in non-development environments. - if (app.Environment.IsDevelopment()) - { - // All health checks must pass for app to be considered ready to accept traffic after starting - _ = app.MapHealthChecks(HealthEndpointPath); - - // Only health checks tagged with the "live" tag must pass for app to be considered alive - _ = app.MapHealthChecks(AlivenessEndpointPath, new HealthCheckOptions - { - Predicate = r => r.Tags.Contains("live") - }); - } - - return app; - } } diff --git a/src/api/Elastic.Documentation.Api.Lambda/Elastic.Documentation.Api.Lambda.csproj b/src/api/Elastic.Documentation.Api.Lambda/Elastic.Documentation.Api.Lambda.csproj index 061b59867..a5856c4da 100644 --- a/src/api/Elastic.Documentation.Api.Lambda/Elastic.Documentation.Api.Lambda.csproj +++ b/src/api/Elastic.Documentation.Api.Lambda/Elastic.Documentation.Api.Lambda.csproj @@ -21,6 +21,7 @@ + diff --git a/src/api/Elastic.Documentation.Api.Lambda/Program.cs b/src/api/Elastic.Documentation.Api.Lambda/Program.cs index b83b798e9..1695b6c59 100644 --- a/src/api/Elastic.Documentation.Api.Lambda/Program.cs +++ b/src/api/Elastic.Documentation.Api.Lambda/Program.cs @@ -9,10 +9,16 @@ using Elastic.Documentation.Api.Core.Search; using Elastic.Documentation.Api.Infrastructure; using Elastic.Documentation.Api.Infrastructure.OpenTelemetry; +using Elastic.Documentation.Configuration.Assembler; +using Elastic.Documentation.ServiceDefaults; try { var builder = WebApplication.CreateSlimBuilder(args); + _ = builder.AddDocumentationServiceDefaults(ref args, (s, p) => + { + _ = s.AddSingleton(AssemblyConfiguration.Create(p)); + }); // Add logging configuration for Lambda _ = builder.AddDocsApiOpenTelemetry(); @@ -39,6 +45,9 @@ builder.Services.AddElasticDocsApiUsecases(environment); var app = builder.Build(); + if (app.Environment.IsDevelopment()) + _ = app.UseDeveloperExceptionPage(); + var v1 = app.MapGroup("/docs/_api/v1"); v1.MapElasticDocsApiEndpoints(); Console.WriteLine("API endpoints mapped"); diff --git a/src/tooling/docs-builder/Program.cs b/src/tooling/docs-builder/Program.cs index a99f7538c..93778ae3c 100644 --- a/src/tooling/docs-builder/Program.cs +++ b/src/tooling/docs-builder/Program.cs @@ -17,7 +17,8 @@ { _ = s.AddSingleton(AssemblyConfiguration.Create(p)); }) - .AddDocumentationToolingDefaults(); + .AddDocumentationToolingDefaults() + .AddOpenTelemetryDefaults(); var app = builder.ToConsoleAppBuilder(); diff --git a/tests-integration/Elastic.Documentation.Api.IntegrationTests/OtlpProxyIntegrationTests.cs b/tests-integration/Elastic.Documentation.Api.IntegrationTests/OtlpProxyIntegrationTests.cs index e60c8518c..f8fbd177d 100644 --- a/tests-integration/Elastic.Documentation.Api.IntegrationTests/OtlpProxyIntegrationTests.cs +++ b/tests-integration/Elastic.Documentation.Api.IntegrationTests/OtlpProxyIntegrationTests.cs @@ -209,8 +209,11 @@ public async Task OtlpProxyReturnsCollectorErrorStatusCode() using var factory = ApiWebApplicationFactory.WithMockedServices(services => { +#pragma warning disable EXTEXP0001 // Experimental API - needed for test to bypass resilience handlers _ = services.AddHttpClient(AdotOtlpGateway.HttpClientName) - .ConfigurePrimaryHttpMessageHandler(() => mockHandler); + .ConfigurePrimaryHttpMessageHandler(() => mockHandler) + .RemoveAllResilienceHandlers(); +#pragma warning restore EXTEXP0001 }); var client = factory.CreateClient(); @@ -219,8 +222,10 @@ public async Task OtlpProxyReturnsCollectorErrorStatusCode() // Act using var response = await client.PostAsync("/docs/_api/v1/o/t", content, TestContext.Current.CancellationToken); + var responseContent = await response.Content.ReadAsStringAsync(TestContext.Current.CancellationToken); // Assert - verify error responses are properly forwarded - response.StatusCode.Should().Be(HttpStatusCode.ServiceUnavailable); + response.StatusCode.Should().Be(HttpStatusCode.ServiceUnavailable, "{0}", responseContent); + // Cleanup mock response mockResponse.Dispose();