Path: redb-route/redb.Route/Telemetry/ProcessorMetrics.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route/Telemetry/ProcessorMetrics.cs
----
using System.Diagnostics.Metrics;
namespace redb.Route.Telemetry;
///
/// Metrics instruments for EIP processors (CircuitBreaker, Throttle, Filter, Debounce, etc.).
/// Subscribe to meter ("redb.Route") to capture these.
///
public static class ProcessorMetrics
{
// ── Circuit Breaker ─────────────────────────────────────────
/// Number of times a circuit breaker tripped to Open state.
public static readonly Counter CircuitBreakerTripped =
RouteMetrics.Meter.CreateCounter("redb.route.circuitbreaker.tripped", "times", "Circuit breaker state transitions to Open.");
/// Exchanges rejected while circuit is Open.
public static readonly Counter CircuitBreakerRejected =
RouteMetrics.Meter.CreateCounter("redb.route.circuitbreaker.rejected", "exchanges", "Exchanges rejected by an open circuit breaker.");
// ── Throttle ────────────────────────────────────────────────
/// Exchanges delayed by throttle (rate limiter).
public static readonly Counter ThrottleDelayed =
RouteMetrics.Meter.CreateCounter("redb.route.throttle.delayed", "exchanges", "Exchanges delayed due to rate limiting.");
// ── Filter ──────────────────────────────────────────────────
/// Exchanges dropped by filter predicates.
public static readonly Counter FilterDropped =
RouteMetrics.Meter.CreateCounter("redb.route.filter.dropped", "exchanges", "Exchanges dropped by a filter predicate.");
// ── Debounce ────────────────────────────────────────────────
/// Exchanges discarded (superseded by a newer message for the same key).
public static readonly Counter DebounceDiscarded =
RouteMetrics.Meter.CreateCounter("redb.route.debounce.discarded", "exchanges", "Exchanges replaced before the quiet period elapsed.");
/// Exchanges flushed (forwarded after quiet period).
public static readonly Counter DebounceFlushed =
RouteMetrics.Meter.CreateCounter("redb.route.debounce.flushed", "exchanges", "Exchanges forwarded after the debounce quiet period.");
// ── Splitter ────────────────────────────────────────────────
/// Total parts produced by splitter processors.
public static readonly Counter SplitterParts =
RouteMetrics.Meter.CreateCounter("redb.route.splitter.parts", "parts", "Total parts produced by splitter processors.");
// ── Timeout ─────────────────────────────────────────────────
/// Exchanges that exceeded the configured timeout.
public static readonly Counter TimeoutExpired =
RouteMetrics.Meter.CreateCounter("redb.route.timeout.expired", "exchanges", "Exchanges that exceeded their processing timeout.");
// ── WireTap ─────────────────────────────────────────────────
/// Clones successfully dispatched to a wire-tap branch (fire-and-forget).
public static readonly Counter WireTapDispatched =
RouteMetrics.Meter.CreateCounter("redb.route.wiretap.dispatched", "exchanges", "Clones successfully handed off to a wire-tap branch.");
/// Wire-tap branch failures. Logged but never propagated to the main pipeline.
public static readonly Counter WireTapFailed =
RouteMetrics.Meter.CreateCounter("redb.route.wiretap.failed", "exchanges", "Wire-tap branches that failed in background. Never affects the main pipeline.");
// ── OnCompletion ────────────────────────────────────────────
/// OnCompletion blocks that failed; logged, never the route's outcome.
public static readonly Counter OnCompletionFailed =
RouteMetrics.Meter.CreateCounter("redb.route.oncompletion.failed", "blocks", "OnCompletion blocks that failed. Never changes the route's outcome.");
// ── Detached pools (WireTap, asynchronous OnCompletion) ─────
// Tagged with the profile ("default" or the executorService name), the step ("wireTap", "onCompletion") and the
// route, so an operator sees which pool fills up and when request threads start paying for a tap.
/// Branches running on a detached step's pool.
public static readonly UpDownCounter PoolActive =
RouteMetrics.Meter.CreateUpDownCounter("redb.route.pool.active", "branches", "Branches running on a detached step's pool.");
/// Branches waiting in a detached step's pool queue.
public static readonly UpDownCounter PoolQueued =
RouteMetrics.Meter.CreateUpDownCounter("redb.route.pool.queued", "branches", "Branches waiting in a detached step's pool queue.");
/// Branches the caller ran itself because the pool and its queue were full (CallerRuns).
public static readonly Counter PoolCallerRuns =
RouteMetrics.Meter.CreateCounter("redb.route.pool.caller_runs", "branches", "Branches the caller ran itself because the pool and its queue were full.");
/// Branches dropped or refused because the pool and its queue were full (Discard, Abort).
public static readonly Counter PoolRejected =
RouteMetrics.Meter.CreateCounter("redb.route.pool.rejected", "branches", "Branches dropped or refused because the pool and its queue were full.");
/// Branches that failed on a detached step's pool.
public static readonly Counter PoolFailed =
RouteMetrics.Meter.CreateCounter("redb.route.pool.failed", "branches", "Branches that failed on a detached step's pool.");
/// Branches still running or waiting when the context's shutdown timeout ran out.
public static readonly Counter PoolNotDrained =
RouteMetrics.Meter.CreateCounter("redb.route.pool.not_drained", "branches", "Branches still running or waiting when the shutdown timeout ran out.");
// ── Multicast ───────────────────────────────────────────────
/// Number of branches dispatched per multicast invocation (histogram).
public static readonly Histogram MulticastBranches =
RouteMetrics.Meter.CreateHistogram("redb.route.multicast.branches", "branches", "Number of target branches dispatched per multicast invocation.");
/// Multicast branches that failed with an unhandled exception.
public static readonly Counter MulticastFailedBranches =
RouteMetrics.Meter.CreateCounter("redb.route.multicast.failed_branches", "branches", "Multicast target branches that failed with an unhandled exception.");
// ── Recipient List ──────────────────────────────────────────
/// Number of recipients resolved per recipient-list invocation (histogram).
public static readonly Histogram RecipientListRecipients =
RouteMetrics.Meter.CreateHistogram("redb.route.recipientlist.recipients", "recipients", "Number of recipients resolved per recipient-list invocation.");
// ── Aggregator ──────────────────────────────────────────────
/// Aggregation groups completed by the completion predicate.
public static readonly Counter AggregatorCompleted =
RouteMetrics.Meter.CreateCounter("redb.route.aggregator.completed", "groups", "Aggregation groups closed by the completion predicate.");
/// Aggregation groups closed by inactivity / completion timeout.
public static readonly Counter AggregatorTimedOut =
RouteMetrics.Meter.CreateCounter("redb.route.aggregator.timed_out", "groups", "Aggregation groups closed because their timeout elapsed before completion.");
/// Aggregation groups currently kept in memory waiting for completion (up/down).
public static readonly UpDownCounter AggregatorInflightGroups =
RouteMetrics.Meter.CreateUpDownCounter("redb.route.aggregator.inflight_groups", "groups", "Aggregation groups currently buffered in memory waiting for completion or timeout.");
// ── Idempotent Consumer ─────────────────────────────────────
/// Exchanges identified as duplicates by the idempotent consumer.
public static readonly Counter IdempotentDuplicate =
RouteMetrics.Meter.CreateCounter("redb.route.idempotent.duplicate", "exchanges", "Exchanges suppressed by the idempotent consumer as duplicates.");
/// Exchanges accepted (first occurrence) by the idempotent consumer.
public static readonly Counter IdempotentPassed =
RouteMetrics.Meter.CreateCounter("redb.route.idempotent.passed", "exchanges", "Exchanges that passed the idempotent consumer for the first time.");
// ── Retry / Redelivery ──────────────────────────────────────
/// Total retry attempts performed by RetryProcessor / OnException redelivery.
public static readonly Counter RetryAttempts =
RouteMetrics.Meter.CreateCounter("redb.route.retry.attempts", "attempts", "Total retry attempts performed before final success or give-up.");
/// Exchanges that succeeded only after one or more retries.
public static readonly Counter RetrySuccess =
RouteMetrics.Meter.CreateCounter("redb.route.retry.success", "exchanges", "Exchanges that ultimately succeeded after at least one retry.");
/// Exchanges that exhausted all retries and failed.
public static readonly Counter RetryExhausted =
RouteMetrics.Meter.CreateCounter("redb.route.retry.exhausted", "exchanges", "Exchanges that exhausted all retry attempts without success.");
// ── Saga ────────────────────────────────────────────────────
/// Sagas that completed successfully end-to-end.
public static readonly Counter SagaCompleted =
RouteMetrics.Meter.CreateCounter("redb.route.saga.completed", "sagas", "Sagas that completed all forward steps successfully.");
/// Sagas that ran compensation after a forward-step failure.
public static readonly Counter SagaCompensated =
RouteMetrics.Meter.CreateCounter("redb.route.saga.compensated", "sagas", "Sagas that triggered compensation actions after a forward-step failure.");
/// Sagas where both a forward step and compensation failed.
public static readonly Counter SagaFailed =
RouteMetrics.Meter.CreateCounter("redb.route.saga.failed", "sagas", "Sagas that failed and could not fully compensate.");
// ── Dead-Letter Channel ─────────────────────────────────────
/// Exchanges routed to a dead-letter channel after retries were exhausted.
public static readonly Counter DeadLetterSent =
RouteMetrics.Meter.CreateCounter("redb.route.deadletter.sent", "exchanges", "Exchanges routed to a dead-letter channel after exhausting retries.");
}