Table of Contents

Observability

BareWire integrates with OpenTelemetry for distributed tracing, metrics, and health checks.

Enabling Observability

builder.Services.AddBareWireObservability(cfg =>
{
    cfg.EnableOpenTelemetry = true;
});

Distributed Tracing

BareWire propagates trace context across message boundaries. Each publish and consume operation creates a span, so you get end-to-end traces across multi-hop workflows.

For example, in the ObservabilityShowcase sample, a single request produces a 3-hop trace:

POST /demo/run
  → DemoOrderCreated (order.created)
    → DemoPaymentProcessed (payment.processed)
      → DemoShipmentDispatched (shipment.dispatched)

Each hop is visible as a child span in your tracing backend (Aspire Dashboard, Jaeger, Zipkin, etc.).

Publish spans are created for PublishAsync, ISendEndpoint.SendAsync, SendRawAsync, PublishRawAsync and the RabbitMQ and in-memory request clients, and the W3C trace context (traceparent, tracestate, baggage) is injected into the outgoing message headers. The span's destination tag contains only the scheme, host and path of the address — never credentials or query strings — and the request client span does not carry the request correlation id.

The consume span is started before the message is dispatched and is Activity.Current while the middleware and the consumer run, so anything a consumer publishes, sends or calls becomes a child of the consume span. With the RabbitMQ transport the trace headers are sent and read even when IgnoreUnmappedHeaders is enabled.

On the consume side, BareWire reads traceparent and falls back to MT-Activity-Id, the header MassTransit uses, when traceparent is absent; traceparent wins when both are present. Messages serialized with the MassTransit envelope also carry MT-Activity-Id, so a trace continues across BareWire and MassTransit services. See MassTransit Interop for details and limits.

Metrics

BareWire emits the following metrics via OpenTelemetry:

Metric Description
barewire.messages.published Counter of published messages
barewire.messages.consumed Counter of consumed messages
barewire.publish.intercepted Counter of outbound messages captured by an outbound message interceptor (for example the transactional outbox buffering a message published from a consumer). Captured messages are not counted in barewire.messages.published
barewire.message.duration Histogram of message processing duration
barewire.messages.redelivery_scheduled Counter of messages scheduled for delayed redelivery
barewire.messages.redelivery_exhausted Counter of messages whose delayed redelivery levels or deferrals were exhausted
barewire.messages.redelivery_failed Counter of failed attempts to schedule a delayed redelivery
barewire.messages.redelivery_deferred Counter of messages deferred to a later delayed redelivery because their inbox claim was still active

Delayed redelivery

An endpoint that uses UseDelayedRedelivery reports its outcomes on four counters. An endpoint without delayed redelivery never records them, and without a listener they allocate nothing.

Counter Tags
barewire.messages.redelivery_scheduled endpoint, message_type, level, error_type
barewire.messages.redelivery_exhausted endpoint, message_type, error_type
barewire.messages.redelivery_failed endpoint, reason
barewire.messages.redelivery_deferred endpoint, reason
  • endpoint is the configured endpoint name and level is the one-based redelivery level (an integer, at most 20).
  • error_type is the type name of the exception that triggered the redelivery — never the exception message.
  • message_type is unknown when the consumer threw, which is the usual way a message reaches delayed redelivery.
  • reason is set only on redelivery_failed and redelivery_deferred and takes a value from a closed set. redelivery_failed: confirm_nack, returned, timeout, channel_closed, publish_error, capacity_wait_cancelled. redelivery_deferred: inbox_claim_active.
  • redelivery_exhausted has no reason tag: the cause is carried by error_type. When the deferral limit is exhausted, error_type is InboxClaimActiveException.
  • Tags never contain message ids, headers or payload.

The number of series of barewire.messages.redelivery_scheduled is driven by endpoint × level × error_type (because message_type is almost always unknown on this path, dropping it does not reduce the count). The OpenTelemetry SDK keeps at most 2000 series per metric by default; once the limit is reached, new series are folded into one series with the attribute otel.metric.overflow=true. If you approach the limit, drop a tag such as level with an OpenTelemetry View, or raise the CardinalityLimit of this instrument with a View.

The settlement of a delayed redelivery runs inside a delayed_redelivery span (source BareWire, kind Internal) with these attributes:

Attribute Set when
messaging.destination always — the endpoint name
barewire.redelivery.level when a copy was published or its publication was attempted (scheduled, deferred, and failed after an attempt); absent for exhausted and when the stage itself failed
barewire.redelivery.outcome always — scheduled, exhausted, failed or deferred
barewire.redelivery.reason outcome failed or deferred — the same value as the reason tag
error.type outcome scheduled or exhausted — the type name of the error that triggered the redelivery

Feature packages add their own instruments on the same BareWire meter — for example barewire.outbox.rows.retried and barewire.outbox.retry.oldest_due_age (see Outbox) and barewire.inbox.duplicates (see Inbox).

Health Checks

BareWire registers health checks that report transport and flow control status:

builder.AddServiceDefaults();  // registers health checks
// ...
app.MapServiceDefaults();      // maps health endpoints

Endpoints:

  • /health — combined liveness + readiness
  • /health/live — liveness only (no dependency checks)
  • /health/ready — full readiness including broker connectivity and flow control

A transport can report its own endpoints too: the in-memory transport reports queues at or above 90% of capacity, and RabbitMQ reports consumers that have been waiting for automatic connection recovery for too long (see Connection recovery and health). Both appear as Degraded.

The bus health description starts with a summary followed by the transport's own description, when the transport reports trouble. The summary mentions capacity only when flow control (in-flight limits) causes the worst status — One or more endpoints are approaching capacity. (Degraded) or One or more endpoints are at capacity. (Unhealthy). When only the transport reports the worst status, the summary is neutral — One or more endpoints are degraded. or One or more endpoints are unhealthy. — for example One or more endpoints are degraded. 1 RabbitMQ consumer(s) waiting for automatic recovery for at least 30 s.

Aspire Dashboard

When running via the Aspire AppHost, traces and metrics are automatically exported to the Aspire Dashboard. No additional configuration is needed — the OTEL_EXPORTER_OTLP_ENDPOINT environment variable is injected automatically.

dotnet run --project samples/BareWire.Samples.AppHost/

Combining with SAGA and Outbox

Observability works seamlessly with SAGA and outbox. The RabbitMQ sample demonstrates all three together:

builder.Services.AddBareWireWithRabbitMq(transport => { /* host, topology, endpoints */ });
builder.Services.AddBareWireSaga<OrderSagaState>(options => options.UseSqlite(...));
builder.Services.AddBareWireOutbox(configureDbContext, configureOutbox);
builder.Services.AddBareWireObservability(cfg => { cfg.EnableOpenTelemetry = true; });

See: samples/BareWire.Samples.ObservabilityShowcase/ and samples/BareWire.Samples.RabbitMQ/