The request pipeline already includes a CorrelationMiddleware responsible for generating and propagating the CorrelationId, enriching both the logging context and the Sentry scope to enable full request traceability in production.
However, logs currently do not include information about the authenticated user when a request requires authentication. This makes it harder to investigate issues related to specific user actions, such as permission errors, data inconsistencies, or failures during sensitive operations.
The proposed improvement is to enrich the logging context inside the PrincipalMiddleware by adding properties related to the authenticated user, such as user_id and optionally user_name. These properties should be added both to the Serilog LogContext and to the Sentry scope.
The request pipeline already includes a
CorrelationMiddlewareresponsible for generating and propagating theCorrelationId, enriching both the logging context and the Sentry scope to enable full request traceability in production.However, logs currently do not include information about the authenticated user when a request requires authentication. This makes it harder to investigate issues related to specific user actions, such as permission errors, data inconsistencies, or failures during sensitive operations.
The proposed improvement is to enrich the logging context inside the
PrincipalMiddlewareby adding properties related to the authenticated user, such asuser_idand optionallyuser_name. These properties should be added both to the SerilogLogContextand to theSentry scope.