39 lines
1.6 KiB
C#
39 lines
1.6 KiB
C#
using ZB.MOM.WW.OtOpcUa.Commons.Observability;
|
|
using ZB.MOM.WW.Telemetry;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.Host.Observability;
|
|
|
|
/// <summary>
|
|
/// Wires the OtOpcUa Meter + ActivitySource into OpenTelemetry and exposes a Prometheus
|
|
/// scrape endpoint at <c>/metrics</c> on the host pipeline. F13d slice — only the meter +
|
|
/// activity source declared in <see cref="OtOpcUaTelemetry"/> are surfaced; per-Akka
|
|
/// internals + ASP.NET request metrics stay off by default to keep the scrape payload
|
|
/// scoped to OtOpcUa-owned signals.
|
|
/// </summary>
|
|
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)
|
|
{
|
|
return services.AddZbTelemetry(o =>
|
|
{
|
|
o.ServiceName = "otopcua";
|
|
o.Meters = [OtOpcUaTelemetry.MeterName];
|
|
o.ActivitySources = [OtOpcUaTelemetry.ActivitySourceName];
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// Mounts the Prometheus scrape endpoint on the existing ASP.NET pipeline. Call after
|
|
/// <c>app.UseAuthentication/UseAuthorization</c> if metrics access should require auth;
|
|
/// the default leaves it unauthenticated for local Prometheus scrapes.
|
|
/// </summary>
|
|
/// <param name="app">The endpoint route builder.</param>
|
|
public static IEndpointRouteBuilder MapOtOpcUaMetrics(this IEndpointRouteBuilder app)
|
|
{
|
|
app.MapZbMetrics();
|
|
return app;
|
|
}
|
|
}
|