Skip to content

[Mocha] Log receive failures and circuit breaker state changes, and fix the conversation ID of the receive span - #10871

Merged
PascalSenn merged 4 commits into
tte/mq-02-backoff-jitterfrom
tte/mq-03-receive-diagnostics
Nov 20, 2026
Merged

PascalSenn merged 4 commits into
tte/mq-02-backoff-jitterfrom
tte/mq-03-receive-diagnostics

Conversation

@tobias-tengler

@tobias-tengler tobias-tengler commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Three changes to what the receive pipeline reports. None of them changes how a message is processed.

Changes

  • Receive path logs. New log entries for faulted, retried, redelivered, discarded and skipped messages: MessageFaulted, FaultDelivered, FaultDeliveryFailed, RetryingMessage, RedeliveringMessage, MessageRedelivered, MessageDiscarded, MessageSkipped. Each is written inside a logger scope with the ids of the message (BeginMessageScope). The new catch in ReceiveFaultMiddleware logs and rethrows.
  • Circuit breaker logs. Both circuit breakers of the receive pipeline log when they open (CircuitOpen, Warning), test recovery (CircuitHalfOpen) and close (CircuitClosed). They logged nothing before.
  • Fix: the tag messaging.message.conversation_id of the receive span holds the conversation ID. It held the correlation ID.
  • Mocha.Sagas.Tests/ReplyDiagnosticsTests.cs is removed. It asserts log output through its own logger provider.

Behavior after this pull request

  • The log volume rises with the failure rate: every faulted message adds one Error entry (MessageFaulted) with its exception.
  • Trace queries that read messaging.message.conversation_id on receive spans see another value.

Docs: observability.md. This pull request also starts the migration guide for 16.8 (migrate-from-16-7-to-16-8.md) with three entries.


Part 3 of 14 of the stack that replaces #10543. It needs nothing from the parts below it and can merge to main on its own.

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Patch coverage

94.3% of changed lines covered (199/211)

File Covered Changed Patch %
src/Mocha/src/Mocha/ThrowHelper.cs 0 4 0.0% 🔴
…/Mocha/Middlewares/Consume/Retry/ConsumerRetryMiddleware.cs 7 8 87.5% 🟡
src/Mocha/src/Mocha/Instrumentation/MessageLogging.cs 62 66 93.9% 🟡
…/Receive/Redelivery/ReceiveRedeliveryMiddleware.cs 16 17 94.1% 🟡
src/Mocha/src/Mocha/Instrumentation/LogScope.cs 22 23 95.7% 🟡
src/Mocha/src/Mocha/Instrumentation/CircuitBreakerLogging.cs 49 50 98.0% 🟡
src/Mocha/src/Mocha/Endpoints/ReceiveEndpoint.cs 1 1 100.0% 🟢
…/Mocha/Instrumentation/ActivityMessagingDiagnosticListener.cs 1 1 100.0% 🟢
…/Mocha/src/Mocha/Middlewares/Consume/Retry/RetryExecutor.cs 3 3 100.0% 🟢
…/Receive/CircuitBreaker/ReceiveCircuitBreakerMiddleware.cs 2 2 100.0% 🟢
…/src/Mocha/Middlewares/Receive/ReceiveDeadLetterMiddleware.cs 1 1 100.0% 🟢
…/src/Mocha/Middlewares/Receive/ReceiveFaultMiddleware.cs 27 27 100.0% 🟢
…/Middlewares/Receive/ReceiveInstrumentationMiddleware.cs 4 4 100.0% 🟢
…/TransportCircuitBreaker/TransportCircuitBreakerMiddleware.cs 4 4 100.0% 🟢
Uncovered changed lines (JSON)
{
  "sha": "64d5d032c17ccf0004e6a87411c47db594647047",
  "files": [
    { "path": "src/Mocha/src/Mocha/ThrowHelper.cs", "ranges": [[292, 295]] },
    { "path": "src/Mocha/src/Mocha/Middlewares/Consume/Retry/ConsumerRetryMiddleware.cs", "ranges": [[42, 42]] },
    { "path": "src/Mocha/src/Mocha/Instrumentation/MessageLogging.cs", "ranges": [[35, 36], [84, 84], [127, 127]] },
    { "path": "src/Mocha/src/Mocha/Middlewares/Receive/Redelivery/ReceiveRedeliveryMiddleware.cs", "ranges": [[53, 53]] },
    { "path": "src/Mocha/src/Mocha/Instrumentation/LogScope.cs", "ranges": [[27, 27]] },
    { "path": "src/Mocha/src/Mocha/Instrumentation/CircuitBreakerLogging.cs", "ranges": [[67, 67]] }
  ]
}

Project coverage: 59.9% (328139/547783 lines)

@tobias-tengler
tobias-tengler force-pushed the tte/mq-03-receive-diagnostics branch 4 times, most recently from f0744aa to ad24d87 Compare November 11, 2026 19:23
@PascalSenn
PascalSenn force-pushed the tte/mq-03-receive-diagnostics branch from 3c8672d to 73489c4 Compare November 12, 2026 22:07
@PascalSenn
PascalSenn marked this pull request as ready for review November 13, 2026 22:08
Copilot AI balanced review requested due to automatic review settings November 13, 2026 22:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Active findings show lost handler correlation when framework logs are filtered, missing batch retry/discard metadata, and a circuit-breaker logging test that incorrectly expects one scope instead of two.

3 open issues
What changed in this PR

This PR improves Mocha’s receive-pipeline observability with correlated operational logs and correct conversation IDs on receive spans, without intending to change message processing.

Changes:

  • Adds message scopes and logs for faults, retries, redelivery, discards, skipped messages, and circuit-breaker transitions.
  • Corrects receive-span conversation IDs and adds logging and tracing tests.
  • Documents the monitoring changes and starts the 16.8 migration guide.
File Description
website/​content/​docs/​mocha/​observability.md Explains operational logging and message scopes.
website/​content/​docs/​mocha/​migration/​structure.yaml Adds the 16.8 migration guide to navigation.
website/​content/​docs/​mocha/​migration/​migrate-from-16-7-to-16-8.md Documents log events and trace changes.
src/​Mocha/​test/​Mocha.Tests/​Middlewares/​Receive/​ReceiveInstrumentationMiddlewareTests.cs Tests conversation IDs and supplies loggers.
src/​Mocha/​test/​Mocha.Tests/​Middlewares/​Receive/​ReceiveFaultMiddlewareTests.cs Updates fault middleware construction.
src/​Mocha/​test/​Mocha.Tests/​Middlewares/​Consume/​Retry/​RetryExecutorTests.cs Adapts tests to expanded retry callbacks.
src/​Mocha/​test/​Mocha.Tests/​Instrumentation/​MessageLogScopeTests.cs Tests message scopes across handler execution.
src/​Mocha/​test/​Mocha.Tests/​Instrumentation/​MessageLoggingTests.cs Tests scope values, formatting, and filtering.
src/​Mocha/​test/​Mocha.Tests/​CircuitBreaker/​CircuitBreakerLoggingTests.cs Tests circuit-opening logs and scopes.
src/​Mocha/​test/​Mocha.Sagas.Tests/​ReplyDiagnosticsTests.cs Removes reply-diagnostics logging tests.
src/​Mocha/​src/​Mocha/​ThrowHelper.cs Adds the scope-index exception factory.
src/​Mocha/​src/​Mocha/​Middlewares/​Receive/​TransportCircuitBreaker/​TransportCircuitBreakerMiddleware.cs Enables transport circuit-breaker logging.
src/​Mocha/​src/​Mocha/​Middlewares/​Receive/​Redelivery/​ReceiveRedeliveryMiddleware.cs Logs redelivery and discard outcomes.
src/​Mocha/​src/​Mocha/​Middlewares/​Receive/​ReceiveInstrumentationMiddleware.cs Creates the receive-message logging scope.
src/​Mocha/​src/​Mocha/​Middlewares/​Receive/​ReceiveFaultMiddleware.cs Logs processing faults and fault-delivery outcomes.
src/​Mocha/​src/​Mocha/​Middlewares/​Receive/​ReceiveDeadLetterMiddleware.cs Logs messages moved to a skipped endpoint.
src/​Mocha/​src/​Mocha/​Middlewares/​Receive/​CircuitBreaker/​ReceiveCircuitBreakerMiddleware.cs Enables consumer circuit-breaker logging.
src/​Mocha/​src/​Mocha/​Middlewares/​Consume/​Retry/​RetryExecutor.cs Exposes exception, delay, and discard callbacks.
src/​Mocha/​src/​Mocha/​Middlewares/​Consume/​Retry/​ConsumerRetryMiddleware.cs Logs consumer retries and discards.
src/​Mocha/​src/​Mocha/​Instrumentation/​MessagingLogs.cs Defines structured operational log events.
src/​Mocha/​src/​Mocha/​Instrumentation/​MessageLogging.cs Captures receive and dispatch scope identifiers.
src/​Mocha/​src/​Mocha/​Instrumentation/​LogScope.cs Provides shared structured scope formatting.
src/​Mocha/​src/​Mocha/​Instrumentation/​CircuitBreakerLogging.cs Adds scoped circuit-state callbacks.
src/​Mocha/​src/​Mocha/​Instrumentation/​ActivityMessagingDiagnosticListener.cs Uses the conversation ID on receive spans.
src/​Mocha/​src/​Mocha/​Endpoints/​ReceiveEndpoint.cs Adds message context to escaped-failure logs.

Review effort: Balanced

Comment on lines +87 to +89
Assert.Equal(
["InstanceId:00000000-0000-0000-0000-000000000001 Transport:memory Endpoint:orders Circuit:Consumer"],
logs.Scopes);
Comment on lines +40 to +42
onRetry: static (s, exception, attempt, delay)
=> s.logger.RetryingMessage(exception, s.context.MessageId, s.consumer.Name, attempt, delay),
onDiscard: static (s, exception) => s.logger.MessageDiscarded(exception, s.context.MessageId),
public async ValueTask InvokeAsync(IReceiveContext context, ReceiveDelegate next)
{
using var activity = events.Receive(context);
using var scope = logger.BeginMessageScope(LogLevel.Critical, context);
tobias-tengler and others added 4 commits November 20, 2026 16:00
…asses and skip them when the level is disabled

The message scopes now copy their values into a small fixed-size scope object instead of a
Dictionary, and their text form lists the values, so the simple console formatter prints them.
BeginMessageScope takes the most severe level logged inside the scope and returns null when that
level is not enabled.
… scope class

The circuit breaker scope now uses the same fixed-size scope object as the message scopes, so its
text form lists the values and the simple console formatter prints them.
…eceive instrumentation middleware

The receive instrumentation middleware now opens the message logging scope around the rest of the
receive pipeline, so every entry written while a message is received, including the entries of the
handlers, carries the message identifiers. The dead letter, fault, redelivery, consumer retry, and
reply consumer logs no longer open their own scope.
@PascalSenn
PascalSenn force-pushed the tte/mq-03-receive-diagnostics branch from 73489c4 to 52bce58 Compare November 20, 2026 15:00
@PascalSenn
PascalSenn merged commit 99d5997 into main Nov 20, 2026
161 of 173 checks passed
@PascalSenn
PascalSenn deleted the tte/mq-03-receive-diagnostics branch November 20, 2026 15:37
michaelstaib added a commit to michaelstaib/graphql-platform that referenced this pull request Nov 23, 2026
* [Website] Fix HTTP response formatter docs for the v16 API (ChilliCream#10951)

* Fix the release failing while installing k6 for the Fusion PGO profile (ChilliCream#10952)

* Fix the AspNetCore tests failing to build for .NET 8 (ChilliCream#10962)

* Rename the Draft20260903 transport version to September2026 (ChilliCream#10963)

* [Fusion] Match fully reused entities on XxHash3 keys and copy producer rows once (ChilliCream#10941)

* Deprecate the Draft20230127 transport version (ChilliCream#10964)

* [Website] Update benchmark results (ChilliCream#10965)

* Enable empty selection sets by default (ChilliCream#10971)

* Add empty selection set support to StrawberryShake (ChilliCream#10972)

* Persist GitHub CLI login across container rebuilds (ChilliCream#10974)

* Fix the Green Donut documentation link in the README (ChilliCream#10973)

* [Fusion] Fix missing operation plan metadata in YAML test snapshot diffs (ChilliCream#10975)

* Use OIDC for Docker Hub login (ChilliCream#10976)

* [Website] Update benchmark results (ChilliCream#10977)

* Coordinate commercial builds and releases (ChilliCream#10970)

* Parallelize repository preparation in prepare-release.sh (ChilliCream#10978)

* Remove the cloud platform update from the release workflow (ChilliCream#10979)

* [Fusion] Reduce allocations on the error path (ChilliCream#10981)

* [Fusion] Fix missing errors for nested shared value types (ChilliCream#10967)

Co-authored-by: tobias-tengler <45513122+tobias-tengler@users.noreply.github.com>

* [Fusion] Fix null propagation for required list items (ChilliCream#10983)

* [Fusion] Fix lookup error paths (ChilliCream#10986)

* [Fusion] Fix missing errors for null required object list items (ChilliCream#10989)

* [Fusion] Fix late subgraph results dropping siblings of nulled objects (ChilliCream#10990)

* [Fusion] Fix late subgraph results reporting false list length mismatches (ChilliCream#10991)

* [Fusion] Fix results with more than 32,767 source documents throwing (ChilliCream#10998)

* [Website] Update npm dependencies to clear advisories (ChilliCream#11002)

* Update .NET SDK to 11.0.100 (ChilliCream#11004)

* [Fusion] Reduce allocations when forwarding errors (ChilliCream#11003)

* [Nitro CLI] Accept Apollo persisted query manifests for client upload/validate (ChilliCream#11005)

* [Mocha] Fix dispatch race during endpoint startup (ChilliCream#11006)

* [Mocha] Fix ExponentialBackoff returning the same delay once it reaches the maximum (ChilliCream#10870)

* [Mocha] Log receive failures and circuit breaker state changes, and fix the conversation ID of the receive span (ChilliCream#10871)

Co-authored-by: Pascal Senn <pascal@chillicream.com>

* [Mocha] Fix RequestAsync waiting for a dispatch that outlasts the response timeout (ChilliCream#10872)

Co-authored-by: Pascal Senn <pascal@chillicream.com>

* [Mocha] Report unhealthy transports in the message bus health check and add a timeout (ChilliCream#10873)

Co-authored-by: Pascal Senn <pascal@chillicream.com>

* [Mocha] Start reply endpoints first, stop them last, and finish cleanup when a stop is cancelled (ChilliCream#10874)

Co-authored-by: Pascal Senn <pascal@chillicream.com>

* [Mocha] Fix the Postgres outbox using up the attempts of a message while the transport is unavailable (ChilliCream#10875)

Co-authored-by: Pascal Senn <pascal@chillicream.com>

* [Mocha] Fix scheduled messages using up their attempts while the transport is unavailable (ChilliCream#10876)

Co-authored-by: Pascal Senn <pascal@chillicream.com>

* [Mocha] Prepare the RabbitMQ transport: internal connection types, RabbitMQ.Client 7.2.2, provisioning with the connection, queue defaults (ChilliCream#10877)

Co-authored-by: Pascal Senn <pascal@chillicream.com>

* [Mocha] Add the RabbitMQ connection manager and failure classification (ChilliCream#10878)

Co-authored-by: Pascal Senn <pascal@chillicream.com>

* [Mocha] Fix RabbitMQ consumers not attaching again after a channel or connection loss (ChilliCream#10879)

Co-authored-by: Pascal Senn <pascal@chillicream.com>

* [Mocha] Fix RabbitMQ sends and publishes completing without the broker's confirmation (ChilliCream#10880)

Co-authored-by: Pascal Senn <pascal@chillicream.com>

* [Mocha] Fix messages for a missing RabbitMQ queue or exchange being dropped (ChilliCream#10881)

Co-authored-by: Pascal Senn <pascal@chillicream.com>

* [Mocha] Fix RabbitMQ requests being sent before the reply consumer is attached (ChilliCream#10882)

Co-authored-by: Pascal Senn <pascal@chillicream.com>

* [Mocha] Move the outbox and scheduler dispatch intervals into their options (ChilliCream#11007)

* Update the .NET 11 packages to the GA release (ChilliCream#11008)

* [Mocha] Fix scalar JSON bodies being cut to their last byte when a stored envelope is read (ChilliCream#11014)

* [Mocha] Fix generated registrations for message types found at publish and send call sites (ChilliCream#11013)

* [Mocha] Fix docs that name APIs and delivery guarantees Mocha does not have (ChilliCream#11015)

* [Mocha] Add UseDispatch, UseReceive and UseConsume to the message bus host builder (ChilliCream#11020)

* Update Aspire and WebUtilities to their patched releases (ChilliCream#11021)

* Set a 7-day NuGet minimum publish age, exempting ChilliCream packages (ChilliCream#11023)

* Replace custom test loggers and clocks with Microsoft testing utilities (ChilliCream#11025)

* [Mocha] Fix saga replies being lost when the sending instance stops (ChilliCream#11022)

* [Fusion] Fix PGO profile handoff to commercial builds (ChilliCream#11027)

* [Fusion] Fix a source schema result staying unreleased when the result callback throws in an alias batch (ChilliCream#11009)

* Fix the fixed-size array pool reserving slots for its largest level up front (ChilliCream#11011)

* Skip unescaping and hashing request documents the parser has seen before (ChilliCream#11010)

* Fix Postgres subscription dispose leaking a connection or hanging (ChilliCream#11026)

* [Mocha] Fix saga replies being discarded when they arrive before the saga state is saved (ChilliCream#11028)

* Snapshot small request feature collections without a frozen dictionary (ChilliCream#10942)

* Fix the cache dropping an entry when a duplicate of its key is evicted (ChilliCream#11039)

* Write the accessed flag of a cache entry only when it is not set (ChilliCream#11040)

* [Fusion] Call Apollo Federation entity lookups without nested async iterators (ChilliCream#11041)

* [Fusion] Read source schema results with the shape that their operation expects (ChilliCream#11043)

* [Website] Add Mocha comparison pages and migration guides (ChilliCream#11024)

* [Fusion] Keep the scratch state of entity lookups per request and build error variable sets on demand (ChilliCream#11042)

* [Fusion] Reference the closed options services of the gateway so Native AOT binaries contain them (ChilliCream#11012)

* [Fusion] Set the operation planner version to 2.13.0

* [Fusion] Update the plan snapshots of the deferred tests to the snapshot format of main

* [Fusion] Fix a sibling field being lost when a late source result has errors below a nulled position

---------

Co-authored-by: Glen <glen.84@gmail.com>
Co-authored-by: Tobias Tengler <45513122+tobias-tengler@users.noreply.github.com>
Co-authored-by: Faris Basha TM <72191505+farisbasha@users.noreply.github.com>
Co-authored-by: vbornand <vbo@netswipe.ch>
Co-authored-by: PascalSenn <senn.pasc@gmail.com>
Co-authored-by: Pascal Senn <pascal@chillicream.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

📚 documentation This issue is about working on our documentation. 🌶️ mocha

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants