a633005f4f
Pins ZB.MOM.WW.Telemetry(.Serilog) 0.2.0 -> 0.3.0. ScadaBridgeTelemetryConfig is now the one place both the AddZbTelemetry registration and the pre-host AddZbSerilog logger fill their options, so ScadaBridge:Telemetry:Exporter=Otlp sends logs to the same collector as metrics and traces, with the same Resource. The pre-host container has no AddZbTelemetry registration for the library's log sink to follow, which is why the exporter is passed to the logger explicitly. site.id / node.role are unchanged (still ScadaBridge:Node:SiteId ?? central / ScadaBridge:Node:Role, applied last so a Telemetry-section key cannot make them diverge from the log enrichers); service.version now defaults to the entry assembly's informational version. Host.Tests 699/699 incl. ScadaBridgeTelemetryConfigTests. Claude-Session: https://claude.ai/code/session_01GT67ACmpMR7b9LGRPLijMi
43 lines
2.2 KiB
C#
43 lines
2.2 KiB
C#
using ZB.MOM.WW.Telemetry;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.Host;
|
|
|
|
/// <summary>
|
|
/// The one place ScadaBridge fills <see cref="ZbTelemetryOptions"/>, shared by the
|
|
/// <c>AddZbTelemetry</c> registration (metrics + traces) and the pre-host <c>AddZbSerilog</c>
|
|
/// logger (logs), so the three signals carry the same Resource and go to the same endpoint.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// The logger is built on its own pre-host container (see <see cref="ScadaBridgeLogging"/>), where
|
|
/// no <c>AddZbTelemetry</c> registration exists for Telemetry 0.3.0's OTLP log sink to follow, so the
|
|
/// exporter settings are passed to <c>AddZbSerilog</c> explicitly (scadaproj#55).
|
|
/// </remarks>
|
|
internal static class ScadaBridgeTelemetryConfig
|
|
{
|
|
/// <summary>The operator section: <c>Exporter</c>, <c>OtlpEndpoint</c>, <c>ServiceVersion</c>,
|
|
/// <c>ExportLogs</c>, <c>ResourceAttributes:*</c>.</summary>
|
|
internal const string SectionName = "ScadaBridge:Telemetry";
|
|
|
|
/// <summary>
|
|
/// Applies the service name, the <c>ScadaBridge:Telemetry</c> keys and then the node identity.
|
|
/// <paramref name="siteId"/> / <paramref name="nodeRole"/> are applied LAST so the Resource always
|
|
/// matches the <c>SiteId</c>/<c>NodeRole</c> log enrichers (both come from <c>ScadaBridge:Node</c>);
|
|
/// a <c>ScadaBridge:Telemetry:SiteId</c>/<c>:NodeRole</c> key cannot make them diverge.
|
|
/// <c>service.version</c> defaults from the entry assembly (the git SHA).
|
|
/// </summary>
|
|
/// <param name="options">The options to fill.</param>
|
|
/// <param name="configuration">The application configuration.</param>
|
|
/// <param name="siteId">The node's site id (<c>ScadaBridge:Node:SiteId</c>, default <c>central</c>).</param>
|
|
/// <param name="nodeRole">The node's role (<c>ScadaBridge:Node:Role</c>).</param>
|
|
internal static void Apply(ZbTelemetryOptions options, IConfiguration configuration, string? siteId, string? nodeRole)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(options);
|
|
ArgumentNullException.ThrowIfNull(configuration);
|
|
|
|
options.ServiceName = ScadaBridgeLogging.ServiceName;
|
|
options.ApplyConfiguration(configuration.GetSection(SectionName));
|
|
options.SiteId = siteId;
|
|
options.NodeRole = nodeRole;
|
|
}
|
|
}
|