From 7ff7a60ae089a84050ff3de5bfad0a7d831f9ca3 Mon Sep 17 00:00:00 2001 From: Joseph Doherty Date: Mon, 1 Jun 2026 16:40:24 -0400 Subject: [PATCH] feat(otopcua): config-driven OTLP exporter opt-in (default Prometheus) --- .../Observability/ObservabilityExtensions.cs | 14 +++++++++++++- src/Server/ZB.MOM.WW.OtOpcUa.Host/Program.cs | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Server/ZB.MOM.WW.OtOpcUa.Host/Observability/ObservabilityExtensions.cs b/src/Server/ZB.MOM.WW.OtOpcUa.Host/Observability/ObservabilityExtensions.cs index 9257cdf6..34f0d665 100644 --- a/src/Server/ZB.MOM.WW.OtOpcUa.Host/Observability/ObservabilityExtensions.cs +++ b/src/Server/ZB.MOM.WW.OtOpcUa.Host/Observability/ObservabilityExtensions.cs @@ -1,3 +1,4 @@ +using Microsoft.Extensions.Configuration; using ZB.MOM.WW.OtOpcUa.Commons.Observability; using ZB.MOM.WW.Telemetry; @@ -14,13 +15,24 @@ public static class ObservabilityExtensions { /// Adds OtOpcUa observability (metrics and tracing) to the service collection. /// The service collection to add observability services to. - public static IServiceCollection AddOtOpcUaObservability(this IServiceCollection services) + /// + /// Configuration read for the opt-in OTLP exporter. OtOpcUa:Telemetry:Exporter + /// (parsed case-insensitively to ) switches to OTLP when set to + /// Otlp; OtOpcUa:Telemetry:OtlpEndpoint sets the OTLP endpoint. With no + /// config the exporter stays Prometheus (the default). + /// + public static IServiceCollection AddOtOpcUaObservability(this IServiceCollection services, IConfiguration configuration) { return services.AddZbTelemetry(o => { o.ServiceName = "otopcua"; o.Meters = [OtOpcUaTelemetry.MeterName]; o.ActivitySources = [OtOpcUaTelemetry.ActivitySourceName]; + if (Enum.TryParse(configuration["OtOpcUa:Telemetry:Exporter"], ignoreCase: true, out var exporter)) + o.Exporter = exporter; + var otlp = configuration["OtOpcUa:Telemetry:OtlpEndpoint"]; + if (!string.IsNullOrWhiteSpace(otlp)) + o.OtlpEndpoint = otlp; }); } diff --git a/src/Server/ZB.MOM.WW.OtOpcUa.Host/Program.cs b/src/Server/ZB.MOM.WW.OtOpcUa.Host/Program.cs index 9ae0abb7..f0bacbd0 100644 --- a/src/Server/ZB.MOM.WW.OtOpcUa.Host/Program.cs +++ b/src/Server/ZB.MOM.WW.OtOpcUa.Host/Program.cs @@ -135,7 +135,7 @@ if (hasAdmin) } builder.Services.AddOtOpcUaHealth(); -builder.Services.AddOtOpcUaObservability(); +builder.Services.AddOtOpcUaObservability(builder.Configuration); var app = builder.Build(); app.UseSerilogRequestLogging();