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 @@ -17,7 +17,7 @@ public async Task InvokeAsync(HttpContext context)
1717 return ;
1818 }
1919
20- var userName = context . User . FindFirst ( ClaimTypes . Name ) ;
20+ var userName = context . User . Claims . FirstOrDefault ( claim => claim . Type == "preferred_username" ) ;
2121 var userId = context . User . FindFirst ( ClaimTypes . NameIdentifier ) ;
2222
2323 if ( userId == null || string . IsNullOrWhiteSpace ( userId . Value ) )
@@ -34,6 +34,21 @@ public async Task InvokeAsync(HttpContext context)
3434
3535 principalProvider . SetPrincipal ( new User ( userId . Value , userName . Value ) ) ;
3636
37- await next ( context ) ;
37+ /* enriches logging and monitoring contexts with user information */
38+ /* enabling traceability of user actions across logs and error monitoring tools */
39+
40+ using ( LogContext . PushProperty ( "user_id" , userId . Value ) )
41+ using ( LogContext . PushProperty ( "user_name" , userName . Value ) )
42+
43+ using ( SentrySdk . PushScope ( ) )
44+ {
45+ SentrySdk . ConfigureScope ( scope =>
46+ {
47+ scope . SetTag ( "user_id" , userId . Value ) ;
48+ scope . SetTag ( "user_name" , userName . Value ) ;
49+ } ) ;
50+
51+ await next ( context ) ;
52+ }
3853 }
3954}
You can’t perform that action at this time.
0 commit comments