From d5625f11469df31047cc5cac22a0110aaaa35629 Mon Sep 17 00:00:00 2001 From: "Minjie.ZHOU" Date: Wed, 10 Jul 2024 16:54:31 +0800 Subject: [PATCH] When OtlpMetricsEndpoint is empty then will not add ResourceMonitoring services; --- src/AgileConfig.Server.Apisite/Startup.cs | 3 +-- src/AgileConfig.Server.Apisite/StartupExtension.cs | 13 +++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/AgileConfig.Server.Apisite/Startup.cs b/src/AgileConfig.Server.Apisite/Startup.cs index 33000c34..72691d0d 100644 --- a/src/AgileConfig.Server.Apisite/Startup.cs +++ b/src/AgileConfig.Server.Apisite/Startup.cs @@ -92,8 +92,7 @@ public void ConfigureServices(IServiceCollection services) services.AddOIDC(); - services.AddResourceMonitoring(); - services.AddSingleton(); + services.AddMeterService(); services.AddOpenTelemetry() .ConfigureResource(resource => resource.AddService(Program.AppName, diff --git a/src/AgileConfig.Server.Apisite/StartupExtension.cs b/src/AgileConfig.Server.Apisite/StartupExtension.cs index 7dfc661a..8df1eef6 100644 --- a/src/AgileConfig.Server.Apisite/StartupExtension.cs +++ b/src/AgileConfig.Server.Apisite/StartupExtension.cs @@ -65,6 +65,19 @@ public static IOpenTelemetryBuilder AddOtlpMetrics(this IOpenTelemetryBuilder bu return builder; } + public static IServiceCollection AddMeterService(this IServiceCollection services) + { + if (string.IsNullOrEmpty(Appsettings.OtlpMetricsEndpoint)) + { + return services; + } + + services.AddResourceMonitoring(); + services.AddSingleton(); + + return services; + } + static HttpMessageHandler NewMessageHandler(bool alwaysTrustSsl) { var handler = new HttpClientHandler();