using ZB.MOM.WW.Telemetry;
namespace ZB.MOM.WW.ScadaBridge.Host;
///
/// The one place ScadaBridge fills , shared by the
/// AddZbTelemetry registration (metrics + traces) and the pre-host AddZbSerilog
/// logger (logs), so the three signals carry the same Resource and go to the same endpoint.
///
///
/// The logger is built on its own pre-host container (see ), where
/// no AddZbTelemetry registration exists for Telemetry 0.3.0's OTLP log sink to follow, so the
/// exporter settings are passed to AddZbSerilog explicitly (scadaproj#55).
///
internal static class ScadaBridgeTelemetryConfig
{
/// The operator section: Exporter, OtlpEndpoint, ServiceVersion,
/// ExportLogs, ResourceAttributes:*.
internal const string SectionName = "ScadaBridge:Telemetry";
///
/// Applies the service name, the ScadaBridge:Telemetry keys and then the node identity.
/// / are applied LAST so the Resource always
/// matches the SiteId/NodeRole log enrichers (both come from ScadaBridge:Node);
/// a ScadaBridge:Telemetry:SiteId/:NodeRole key cannot make them diverge.
/// service.version defaults from the entry assembly (the git SHA).
///
/// The options to fill.
/// The application configuration.
/// The node's site id (ScadaBridge:Node:SiteId, default central).
/// The node's role (ScadaBridge:Node:Role).
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;
}
}