Improve correlationId handling for async - #1278
Merged
Merged
Conversation
JackLewis-digirati
approved these changes
Aug 21, 2026
CorrelationId was sometimes being lost when there is not HttpContext, this was noticed when looking at OrchestrationQueueMonitor output but could also happen in LazyCache callback factories or ContinueWith() calls. Rather than rely on context, add a middleware to setup id before anything happens, this is then set for all remaining requests
donaldgray
force-pushed
the
feature/improve_correlation
branch
from
August 24, 2026 13:12
3611219 to
12a02cc
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.
What does this change?
CorrelationId was sometimes being lost when there is no HttpContext, this was noticed when looking at
OrchestrationQueueMonitoroutput but could also happen in LazyCache callback factories or ContinueWith() calls. Nothing broke but logs would be missing a correlationId, which made it difficult to track which HTTP call caused specific actions.Rather than rely on context, add a middleware to setup id before anything happens, this is then set for all remaining requests
CorrelationIdMiddlewarenow setsCorrelationIdContextearly in pipeline. This will read provided value or mint a new one. This is read by the serilog enricher when writing logs, previously this needed an HttpContext which isn't available in async continuations or background tasks.