feat(otopcua): config-driven OTLP exporter opt-in (default Prometheus)

This commit is contained in:
Joseph Doherty
2026-06-01 16:40:24 -04:00
parent 8faa2bf23d
commit 7ff7a60ae0
2 changed files with 14 additions and 2 deletions
@@ -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
{
/// <summary>Adds OtOpcUa observability (metrics and tracing) to the service collection.</summary>
/// <param name="services">The service collection to add observability services to.</param>
public static IServiceCollection AddOtOpcUaObservability(this IServiceCollection services)
/// <param name="configuration">
/// Configuration read for the opt-in OTLP exporter. <c>OtOpcUa:Telemetry:Exporter</c>
/// (parsed case-insensitively to <see cref="ZbExporter"/>) switches to OTLP when set to
/// <c>Otlp</c>; <c>OtOpcUa:Telemetry:OtlpEndpoint</c> sets the OTLP endpoint. With no
/// config the exporter stays Prometheus (the default).
/// </param>
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<ZbExporter>(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;
});
}
+1 -1
View File
@@ -135,7 +135,7 @@ if (hasAdmin)
}
builder.Services.AddOtOpcUaHealth();
builder.Services.AddOtOpcUaObservability();
builder.Services.AddOtOpcUaObservability(builder.Configuration);
var app = builder.Build();
app.UseSerilogRequestLogging();