From bf66318da67a666978b4de819e4fb08aeee4e55b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20N=C3=B8rgaard?= Date: Wed, 22 May 2024 08:55:34 +0200 Subject: [PATCH] Setup conditional endpoint registration for HostExtensions.cs logging --- src/Ast.Platform/HostExtensions.cs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Ast.Platform/HostExtensions.cs b/src/Ast.Platform/HostExtensions.cs index 574bc3b..7e5e8e9 100644 --- a/src/Ast.Platform/HostExtensions.cs +++ b/src/Ast.Platform/HostExtensions.cs @@ -11,10 +11,6 @@ public static IHostBuilder UsePlatformLogger(this IHostBuilder builder) { const string key = $"{nameof(ServiceOptions)}__{nameof(ServiceOptions.TelemetryCollectorHost)}"; var collectorEndpoint = Environment.GetEnvironmentVariable(key); - if (string.IsNullOrWhiteSpace(collectorEndpoint)) - { - throw new Exception($"Env var {key} was empty."); - } return builder.ConfigureLogging(loggingBuilder => { @@ -22,7 +18,9 @@ public static IHostBuilder UsePlatformLogger(this IHostBuilder builder) { loggerOptions.IncludeScopes = true; loggerOptions.IncludeFormattedMessage = true; - loggerOptions.AddOtlpExporter(options => options.Endpoint = new Uri(collectorEndpoint)); + + if (string.IsNullOrWhiteSpace(collectorEndpoint)) loggerOptions.AddOtlpExporter(); + else loggerOptions.AddOtlpExporter(options => options.Endpoint = new Uri(collectorEndpoint)); } ); });