File tree Expand file tree Collapse file tree
Boundaries/Comanda.Subscriptions/Source/Comanda.Subscriptions.WebApi Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ namespace Comanda . Subscriptions . WebApi . Constants ;
2+
3+ public static class Headers
4+ {
5+ public const string Credential = "X-Credential" ;
6+ public const string Location = "Location" ;
7+ public const string Link = "Link" ;
8+ public const string Pagination = "X-Pagination" ;
9+ public const string Authorization = "Authorization" ;
10+ public const string Idempotency = "Idempotency-Key" ;
11+ public const string Correlation = "Correlation" ;
12+ }
Original file line number Diff line number Diff line change @@ -13,9 +13,10 @@ public static void UseHttpPipeline(this IApplicationBuilder app)
1313 app . UseAuthentication ( ) ;
1414 app . UseAuthorization ( ) ;
1515
16+ app . UseCorrelationMiddleware ( ) ;
1617 app . UseEndpoints ( endpoints =>
1718 {
1819 endpoints . MapControllers ( ) ;
1920 } ) ;
2021 }
21- }
22+ }
Original file line number Diff line number Diff line change 1+ namespace Comanda . Subscriptions . 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 . Subscriptions . 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+ }
Original file line number Diff line number Diff line change 66
77global using Comanda . Subscriptions . WebApi . Extensions ;
88global using Comanda . Subscriptions . WebApi . Constants ;
9+ global using Comanda . Subscriptions . WebApi . Middlewares ;
910global using Comanda . Subscriptions . Domain . Errors ;
1011
1112global using Comanda . Subscriptions . Application . Payloads . Traceability ;
1920
2021global using Scalar . AspNetCore ;
2122global using Serilog ;
23+ global using Serilog . Context ;
2224global using FluentValidation . AspNetCore ;
You can’t perform that action at this time.
0 commit comments