feat(telemetry): 0.3.0 service.version default, ResourceAttributes, logs follow AddZbTelemetry OTLP (#55)
- service.version: null ServiceVersion now defaults to the entry assembly's AssemblyInformationalVersion (the family apps stamp the git SHA there); "" omits it. - ResourceAttributes: extra Resource attributes on every signal; first-class keys (service.*, host.name, site.id, node.role) are reserved and rejected at startup. - Logs over OTLP: AddZbTelemetry publishes its options in DI and AddZbSerilog's OTLP log sink follows them when its own options do not select Otlp, so <App>:Telemetry:Exporter=Otlp now switches logs along with metrics and traces, with the same endpoint and Resource. ExportLogs=false opts out. - Ships the unpublished 0.2.1 review fixes, including the stricter OTLP endpoint check (scheme-less host:port rejected when Exporter=Otlp); no app config sets an endpoint. - Tests 42 -> 74, incl. a loopback OTLP/gRPC receiver proving logs arrive with the Resource, and an ExportLogs=false case with a metrics positive control. Claude-Session: https://claude.ai/code/session_01GT67ACmpMR7b9LGRPLijMi
This commit is contained in:
@@ -49,7 +49,20 @@ internal static class ZbSerilogConfig
|
||||
public static LoggerConfiguration Apply(
|
||||
LoggerConfiguration loggerConfiguration,
|
||||
ZbTelemetryOptions options,
|
||||
IServiceProvider? serviceProvider)
|
||||
IServiceProvider? serviceProvider) =>
|
||||
Apply(loggerConfiguration, options, serviceProvider, registeredTelemetry: null);
|
||||
|
||||
/// <summary>
|
||||
/// Full overload: <paramref name="registeredTelemetry"/> is the options an <c>AddZbTelemetry</c>
|
||||
/// call registered in the same container (or <see langword="null"/>). The OTLP log sink follows
|
||||
/// it when <paramref name="options"/> does not select OTLP itself — see
|
||||
/// <see cref="ResolveLogExport"/>. Identity enrichers always come from <paramref name="options"/>.
|
||||
/// </summary>
|
||||
public static LoggerConfiguration Apply(
|
||||
LoggerConfiguration loggerConfiguration,
|
||||
ZbTelemetryOptions options,
|
||||
IServiceProvider? serviceProvider,
|
||||
ZbTelemetryOptions? registeredTelemetry)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(loggerConfiguration);
|
||||
ArgumentNullException.ThrowIfNull(options);
|
||||
@@ -75,7 +88,10 @@ internal static class ZbSerilogConfig
|
||||
ApplyRedaction(loggerConfiguration, serviceProvider);
|
||||
}
|
||||
|
||||
ApplyOpenTelemetryExport(loggerConfiguration, options);
|
||||
if (ResolveLogExport(options, registeredTelemetry) is { } export)
|
||||
{
|
||||
ApplyOpenTelemetryExport(loggerConfiguration, export);
|
||||
}
|
||||
|
||||
return loggerConfiguration;
|
||||
}
|
||||
@@ -90,6 +106,33 @@ internal static class ZbSerilogConfig
|
||||
internal static void ApplyRedaction(LoggerConfiguration loggerConfiguration, IServiceProvider serviceProvider) =>
|
||||
loggerConfiguration.Enrich.With(new RedactionEnricher(serviceProvider));
|
||||
|
||||
/// <summary>
|
||||
/// Chooses the options the OTLP log sink is built from, or <see langword="null"/> for no sink:
|
||||
/// <list type="number">
|
||||
/// <item><paramref name="serilogOptions"/> when it selects <see cref="ZbExporter.Otlp"/> itself
|
||||
/// (the pre-0.3.0 behaviour; an app that builds its logger outside the host container, such as
|
||||
/// ScadaBridge, passes the exporter here);</item>
|
||||
/// <item>else the <c>AddZbTelemetry</c> registration in the same container when it selects
|
||||
/// OTLP — so <c><App>:Telemetry:Exporter=Otlp</c> switches logs along with metrics and
|
||||
/// traces, with the identical Resource (scadaproj#55);</item>
|
||||
/// <item>else none.</item>
|
||||
/// </list>
|
||||
/// Whichever is chosen, its <see cref="ZbTelemetryOptions.ExportLogs"/> = <see langword="false"/>
|
||||
/// keeps logs local.
|
||||
/// </summary>
|
||||
internal static ZbTelemetryOptions? ResolveLogExport(
|
||||
ZbTelemetryOptions serilogOptions,
|
||||
ZbTelemetryOptions? registeredTelemetry)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(serilogOptions);
|
||||
|
||||
var source = serilogOptions.Exporter == ZbExporter.Otlp
|
||||
? serilogOptions
|
||||
: registeredTelemetry is { Exporter: ZbExporter.Otlp } ? registeredTelemetry : null;
|
||||
|
||||
return source is { ExportLogs: true } ? source : null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a <c>WriteTo.OpenTelemetry</c> log sink when an OTLP exporter is explicitly
|
||||
/// selected (<see cref="ZbTelemetryOptions.Exporter"/> = <see cref="ZbExporter.Otlp"/>).
|
||||
|
||||
Reference in New Issue
Block a user