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();