feat(servicedefaults): add SeqOptions configuration and integrate with OpenTelemetry logging and tracing

This commit is contained in:
Stevan Freeborn
2026-03-11 18:52:05 -05:00
parent e30f19e939
commit 64c64e8d95
6 changed files with 66 additions and 3 deletions
@@ -1,3 +1,8 @@
using Microsoft.Extensions.Configuration;
using OpenTelemetry.Exporter;
using OpenTelemetry.Logs;
namespace FiscalOS.ServiceDefaults;
public static class ServiceDefaultsExtensions
@@ -76,11 +81,38 @@ public static class ServiceDefaultsExtensions
private static TBuilder AddOpenTelemetryExporters<TBuilder>(this TBuilder builder) where TBuilder : IHostApplicationBuilder
{
var seqOptions = new SeqOptions();
builder.Configuration.GetSection(nameof(SeqOptions)).Bind(seqOptions);
var useOtlpExporter = !string.IsNullOrWhiteSpace(builder.Configuration["OTEL_EXPORTER_OTLP_ENDPOINT"]);
if (useOtlpExporter)
var otel = builder.Services.AddOpenTelemetry();
if (seqOptions.IsEnabled)
{
builder.Services.AddOpenTelemetry().UseOtlpExporter();
otel
.WithLogging(lb =>
{
lb.AddOtlpExporter(o =>
{
o.Protocol = OtlpExportProtocol.HttpProtobuf;
o.Endpoint = new Uri(seqOptions.LogEndpoint);
o.Headers = seqOptions.AuthHeader;
});
})
.WithTracing(tb =>
{
tb.AddOtlpExporter(o =>
{
o.Protocol = OtlpExportProtocol.HttpProtobuf;
o.Endpoint = new Uri(seqOptions.TraceEndpoint);
o.Headers = seqOptions.AuthHeader;
});
});
}
else if (useOtlpExporter)
{
otel.UseOtlpExporter();
}
return builder;