From d0e945c4e2d6a89b4ed8a43531b802b56d74f9a7 Mon Sep 17 00:00:00 2001 From: John Lambert Date: Fri, 20 Oct 2023 08:14:35 -0400 Subject: [PATCH 1/3] a start --- src/Serval.ApiServer/Serval.ApiServer.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Serval.ApiServer/Serval.ApiServer.csproj b/src/Serval.ApiServer/Serval.ApiServer.csproj index ae23fe3f..fae6e9b8 100644 --- a/src/Serval.ApiServer/Serval.ApiServer.csproj +++ b/src/Serval.ApiServer/Serval.ApiServer.csproj @@ -22,6 +22,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive + From e33c677f8c80bd91566f944060441cd620ef9e2e Mon Sep 17 00:00:00 2001 From: John Lambert Date: Fri, 20 Oct 2023 09:41:25 -0400 Subject: [PATCH 2/3] Metrics being exported --- src/Serval.ApiServer/Serval.ApiServer.csproj | 2 +- src/Serval.ApiServer/Startup.cs | 8 ++++++++ src/Serval.ApiServer/Usings.cs | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Serval.ApiServer/Serval.ApiServer.csproj b/src/Serval.ApiServer/Serval.ApiServer.csproj index fae6e9b8..3d56f956 100644 --- a/src/Serval.ApiServer/Serval.ApiServer.csproj +++ b/src/Serval.ApiServer/Serval.ApiServer.csproj @@ -22,7 +22,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/src/Serval.ApiServer/Startup.cs b/src/Serval.ApiServer/Startup.cs index 9cdd3722..adca32e8 100644 --- a/src/Serval.ApiServer/Startup.cs +++ b/src/Serval.ApiServer/Startup.cs @@ -172,6 +172,12 @@ public void ConfigureServices(IServiceCollection services) .AddSource("MongoDB.Driver.Core.Extensions.DiagnosticSources") .AddConsoleExporter(); }); + else + { + services + .AddOpenTelemetry() + .WithMetrics(opts => opts.AddAspNetCoreInstrumentation().AddPrometheusExporter()); + } } public void Configure(IApplicationBuilder app, IWebHostEnvironment env) @@ -214,6 +220,8 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) settings.CustomJavaScriptPath = "js/auth0.js"; }); + + app.UseOpenTelemetryPrometheusScrapingEndpoint(); } private static Task WriteHealthCheckResponse(HttpContext context, HealthReport healthReport) diff --git a/src/Serval.ApiServer/Usings.cs b/src/Serval.ApiServer/Usings.cs index d64037a7..02d39d58 100644 --- a/src/Serval.ApiServer/Usings.cs +++ b/src/Serval.ApiServer/Usings.cs @@ -20,8 +20,8 @@ global using NSwag; global using NSwag.AspNetCore; global using NSwag.Generation.Processors.Security; -global using OpenTelemetry; global using OpenTelemetry.Trace; +global using OpenTelemetry.Metrics; global using Serval.Shared.Contracts; global using Serval.Shared.Controllers; global using Serval.Shared.Models; From f24432f760ae1dfdf214fa828a12d691edc4c8ca Mon Sep 17 00:00:00 2001 From: John Lambert Date: Fri, 20 Oct 2023 09:58:45 -0400 Subject: [PATCH 3/3] Only export metrics if we want them --- src/Serval.ApiServer/Startup.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Serval.ApiServer/Startup.cs b/src/Serval.ApiServer/Startup.cs index adca32e8..fb7638f8 100644 --- a/src/Serval.ApiServer/Startup.cs +++ b/src/Serval.ApiServer/Startup.cs @@ -221,7 +221,8 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) settings.CustomJavaScriptPath = "js/auth0.js"; }); - app.UseOpenTelemetryPrometheusScrapingEndpoint(); + if (!Environment.IsDevelopment()) + app.UseOpenTelemetryPrometheusScrapingEndpoint(); } private static Task WriteHealthCheckResponse(HttpContext context, HealthReport healthReport)