Log an error when an exception bypasses the dead letter queue - #354
Draft
nabisobhi wants to merge 1 commit into
Draft
Log an error when an exception bypasses the dead letter queue#354nabisobhi wants to merge 1 commit into
nabisobhi wants to merge 1 commit into
Conversation
Consumer now accepts an optional ILogger<Consumer> (defaulting to NullLogger) and logs an error with the exception type, partition key and source topic when a registered bypass exception is about to propagate and crash the consumer. The real logger is resolved in both AddConsumer overloads. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
nabisobhi
force-pushed
the
nabisobhi-dlq-observability
branch
from
September 10, 2026 12:22
ce37df9 to
47df637
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #353 — please review that one first. This PR''s diff is against
nabisobhi-bookish-waddle, so it shows only the logging change.Why
#353 lets registered exception types bypass the dead letter queue and propagate, crashing the consumer. Until now that happened silently from the
Consumer''s point of view — there was no record of why the consumer died or which message triggered it.Change
Consumernow takes an optionalILogger<Consumer>(defaulting toNullLogger<Consumer>.Instance, so existing call sites and tests are unaffected) and logs before rethrowing:Logged at Error level with the exception attached. The real logger is resolved in both
AddConsumeroverloads.To log at that point, the bypass check moved out of the exception filter into the catch body, which now rethrows with a bare
throw;. That preserves the original stack trace, and behavior is otherwise identical.Overlap worth a reviewer''s opinion
ConsumerHostedService.ConsumeAllalready logs any escaping exception as"Unhandled error occurred while consuming messaging", so a bypassed exception will now produce two Error entries: this context-rich one, then the generic boundary one. That''s a common pattern (detail at the site, generic at the boundary), but if you''d rather avoid the duplication, options are to drop this to Warning or skip this PR entirely — #353 is fully functional without it.Notes
Microsoft.Extensions.Logging.Abstractionsis already referenced.Consumerisinternal.LoggerSpy<T>test double rather thanMock<ILogger<Consumer>>, because Moq can''t proxy a generic closed over an internal type withoutInternalsVisibleTo("DynamicProxyGenAssembly2").Tests
Two new tests: the bypass logs the expected level/exception/message, and dead-lettered messages do not log the bypass error.
TestConsumer37/37, full suite 156/156, build clean with 0 warnings.