Skip to content

Improve correlationId handling for async - #1278

Merged
donaldgray merged 2 commits into
developfrom
feature/improve_correlation
Aug 24, 2026
Merged

Improve correlationId handling for async#1278
donaldgray merged 2 commits into
developfrom
feature/improve_correlation

Conversation

@donaldgray

Copy link
Copy Markdown
Member

What does this change?

CorrelationId was sometimes being lost when there is no HttpContext, this was noticed when looking at OrchestrationQueueMonitor output 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

CorrelationIdMiddleware now sets CorrelationIdContext early 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.

@donaldgray
donaldgray requested a review from a team as a code owner August 18, 2026 06:17
Comment thread src/protagonist/DLCS.Web/Middleware/CorrelationIdMiddleware.cs Outdated
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
donaldgray force-pushed the feature/improve_correlation branch from 3611219 to 12a02cc Compare August 24, 2026 13:12
@donaldgray
donaldgray merged commit 50481e6 into develop Aug 24, 2026
8 checks passed
@donaldgray
donaldgray deleted the feature/improve_correlation branch August 24, 2026 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants