arolariu.Backend.Common.Telemetry.Metering
arolariu.Backend.Common
arolariu.Backend.Common.Telemetry.Metering Namespace
Classes
HealthCheckMetrics Class
Emits the single always-on signal that survives health telemetry suppression.
public static class HealthCheckMetrics
Inheritance System.Object 🡒 HealthCheckMetrics
Remarks
All other health telemetry is dropped. This counter stays enabled because its volume is
effectively zero until a dependency actually fails. The metric name is deliberately shared
verbatim with the website and exp services so a single query spans the estate; the
service.name resource attribute distinguishes the source.
Constructors
HealthCheckMetrics() Constructor
static HealthCheckMetrics();
Fields
HealthCheckMetrics.FailedChecksItemKey Field
The Microsoft.AspNetCore.Http.HttpContext.Items key used to hand failing check names from the health check response writer to the suppression middleware.
public const string FailedChecksItemKey = "arolariu.health.failed-checks";
Field Value
HealthCheckMetrics.FailureCounter Field
private static readonly Counter<long> FailureCounter;
Field Value
System.Diagnostics.Metrics.Counter<System.Int64>
HealthCheckMetrics.MetricName Field
The exported metric name.
public const string MetricName = "arolariu.health.check.failures";
Field Value
Methods
HealthCheckMetrics.RecordFailures(IEnumerable<string>) Method
Records one measurement per failing health check.
public static void RecordFailures(System.Collections.Generic.IEnumerable<string> failedCheckNames);
Parameters
failedCheckNames System.Collections.Generic.IEnumerable<System.String>
The names of the health checks that reported failure.
Exceptions
System.ArgumentNullException
Thrown when failedCheckNames is null.
Remarks
Must be called outside any active SuppressInstrumentationScope, otherwise the
measurement may be discarded along with the suppressed request telemetry.
MeterGenerators Class
Provides centralized System.Diagnostics.Metrics.Meter instances for custom metrics across application components.
This mirrors ActivityGenerators which provides per-bounded-context ActivitySource instances.
public static class MeterGenerators
Inheritance System.Object 🡒 MeterGenerators
Example
// Creating a counter from the Invoice meter
private static readonly Counter<long> InvoicesCreated =
MeterGenerators.InvoiceMeter.CreateCounter<long>("invoices.created", description: "Total invoices created");
// Recording an observation
InvoicesCreated.Add(1, new KeyValuePair<string, object?>("user.id", userId.ToString()));
Remarks
Each bounded context has its own System.Diagnostics.Metrics.Meter to ensure metric isolation and clear ownership:
- CommonMeter — Infrastructure metrics (config refresh, Key Vault, etc.)
- CoreMeter — Core application metrics (health checks, startup)
- AuthMeter — Authentication/authorization metrics (logins, token operations)
- InvoiceMeter — Invoice domain metrics (CRUD counts, analysis duration, RU cost)
All meters are registered in AddOTelMetering(this WebApplicationBuilder) via AddMeter().
Constructors
MeterGenerators() Constructor
static MeterGenerators();
Fields
MeterGenerators.AuthMeter Field
Meter for the Authentication package — auth event metrics.
public static readonly Meter AuthMeter;
Field Value
System.Diagnostics.Metrics.Meter
MeterGenerators.CommonMeter Field
Meter for the Common package — infrastructure and configuration metrics.
public static readonly Meter CommonMeter;
Field Value
System.Diagnostics.Metrics.Meter
MeterGenerators.CoreMeter Field
Meter for the Core package — application lifecycle and health metrics.
public static readonly Meter CoreMeter;
Field Value
System.Diagnostics.Metrics.Meter
MeterGenerators.InvoiceMeter Field
Meter for the Invoices domain package — business operation metrics.
public static readonly Meter InvoiceMeter;
Field Value
System.Diagnostics.Metrics.Meter
MeteringExtensions Class
Provides extension methods for configuring OpenTelemetry metrics collection with Azure Monitor integration. This class sets up performance monitoring and metrics export to Azure Application Insights.
public static class MeteringExtensions
Inheritance System.Object 🡒 MeteringExtensions
Example
// Usage in Program.cs
var builder = WebApplication.CreateBuilder(args);
builder.AddOTelMetering();
Remarks
This extension configures: - ASP.NET Core metrics for HTTP request performance monitoring - HTTP client metrics for dependency call tracking - Azure Monitor exporter for cloud-based metrics aggregation - Console exporter for local development and debugging
Methods
MeteringExtensions.AddOTelMetering(this WebApplicationBuilder) Method
Configures OpenTelemetry metrics collection with automatic instrumentation and Azure Monitor export. This method enables comprehensive performance monitoring for ASP.NET Core applications and HTTP clients.
public static void AddOTelMetering(this Microsoft.AspNetCore.Builder.WebApplicationBuilder builder);
Parameters
builder Microsoft.AspNetCore.Builder.WebApplicationBuilder
The Microsoft.AspNetCore.Builder.WebApplicationBuilder to configure with OpenTelemetry metrics.
Exceptions
System.ArgumentNullException
Thrown when builder is null.
Remarks
This method configures metrics collection for: - ASP.NET Core instrumentation: HTTP request duration, response codes, and throughput - HTTP client instrumentation: Outbound request performance and dependency tracking - Console export during debugging for immediate feedback - Azure Monitor export for production monitoring and alerting - Managed Identity authentication for secure cloud integration