Skip to main content
Version: 0.7.0

Framework Metrics

Sharkable provides built-in counters powered by System.Diagnostics.Metrics. Zero external dependencies, fully AOT-compatible, and automatically flows into OpenTelemetry when exporters are configured.

Quick Start

builder.Services.AddShark(opt =>
{
opt.ConfigureMetrics(m => m.Enabled = true);
});

This creates a Meter("Sharkable") with the following counters. Disabled by default.

Counters

CounterDescription
sharkable.requestsTotal requests processed by the pipeline
sharkable.ratelimit.rejectedRequests rejected by the distributed rate limiter
sharkable.idempotency.hitIdempotency-key cache hits (replayed responses)
sharkable.idempotency.missIdempotency-key cache misses (new requests)
sharkable.idempotency.conflictIdempotency-key conflicts (different payload, same key)
sharkable.auth.failuresAuthentication/authorization failures
sharkable.audit.droppedAudit log entries dropped due to channel overflow
sharkable.cron.runsCron job executions
sharkable.cron.failuresFailed cron job executions
sharkable.saga.completedSuccessfully completed saga transactions
sharkable.saga.compensatedCompensated (rolled back) saga transactions

Configuration

opt.ConfigureMetrics(m =>
{
m.Enabled = true;
m.MeterName = "MyApp"; // default: "Sharkable"
m.MeterVersion = "2.0"; // default: "1.0"
});

Custom Metrics

Replace the entire metrics implementation via the factory pattern:

builder.Services.AddShark(opt =>
{
opt.ConfigureMetrics(m => m.Enabled = true);
opt.MetricsFactory = sp => new PrometheusSharkMetrics();
});

// Custom implementation
public sealed class PrometheusSharkMetrics : ISharkMetrics
{
public Counter<long> Requests { get; }
public Counter<long> RateLimitRejected { get; }
// ... implement all ISharkMetrics counters
}

Your custom implementation receives the same MeterName/MeterVersion from MetricsOptions.

Integration with OpenTelemetry

Add the OpenTelemetry exporter to your project:

dotnet add package OpenTelemetry.Exporter.Prometheus.AspNetCore
builder.Services.AddOpenTelemetry()
.WithMetrics(m => m
.AddMeter("Sharkable") // match your MetricsOptions.MeterName
.AddPrometheusExporter());

All Sharkable counters flow into your metrics backend automatically — no code changes needed in your endpoints.

AOT

Fully AOT-compatible. System.Diagnostics.Metrics is a first-class .NET API with no reflection.