File tree Expand file tree Collapse file tree
Boundaries/Comanda.Orchestrator/Source/Comanda.Orchestrator.WebApi/Middlewares Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ namespace Comanda . Orchestrator . WebApi . Middlewares ;
2+
3+ public sealed class CorrelationMiddleware ( RequestDelegate next )
4+ {
5+ public async Task InvokeAsync ( HttpContext context )
6+ {
7+ var correlationId = context . Request . Headers [ Headers . Correlation ] . FirstOrDefault ( ) ;
8+
9+ if ( string . IsNullOrWhiteSpace ( correlationId ) )
10+ correlationId = context . TraceIdentifier ;
11+
12+ context . Items [ Headers . Correlation ] = correlationId ;
13+ context . Response . Headers [ Headers . Correlation ] = correlationId ;
14+
15+ /* enriches the logging scope with the current correlation identifier, ensuring all logs within this request pipeline share the same identifier */
16+ /* more details: https://microsoft.github.io/code-with-engineering-playbook/observability/correlation-id/ */
17+
18+ using ( LogContext . PushProperty ( Headers . Correlation , correlationId ) )
19+ using ( SentrySdk . PushScope ( ) )
20+ {
21+ SentrySdk . ConfigureScope ( scope =>
22+ {
23+ scope . SetTag ( "correlation_id" , correlationId ) ;
24+ } ) ;
25+
26+ await next ( context ) ;
27+ }
28+ }
29+ }
Original file line number Diff line number Diff line change 1+ namespace Comanda . Orchestrator . WebApi . Middlewares ;
2+
3+ [ ExcludeFromCodeCoverage ( Justification = "contains only dependency injection" ) ]
4+ public static class CorrelationMiddlewareExtension
5+ {
6+ public static IApplicationBuilder UseCorrelationMiddleware ( this IApplicationBuilder app )
7+ {
8+ return app . UseMiddleware < CorrelationMiddleware > ( ) ;
9+ }
10+ }
You can’t perform that action at this time.
0 commit comments