Skip to content

Commit

Permalink
Setup conditional endpoint registration for HostExtensions.cs logging
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornnorgaard committed May 22, 2024
1 parent 4b18ea4 commit bf66318
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/Ast.Platform/HostExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,16 @@ 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 =>
{
loggingBuilder.AddOpenTelemetry(loggerOptions =>
{
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));
}
);
});
Expand Down

0 comments on commit bf66318

Please sign in to comment.