ASP.NET Core Web API Interview Question #133
What is a correlation ID or trace ID?
Error Handling, Logging, Caching, Rate Limiting, CORS & Reliability Senior Advanced
Quick Interview Answer
A correlation or trace identifier lets related log entries and distributed operations be connected to the same request or workflow. ASP.NET Core exposes request tracing information through HttpContext, and distributed tracing can propagate context across service boundaries.
Detailed Explanation
A correlation or trace identifier lets related log entries and distributed operations be connected to the same request or workflow. ASP.NET Core exposes request tracing information through HttpContext, and distributed tracing can propagate context across service boundaries.
Returning a safe trace identifier in an error response can help support teams locate the corresponding server-side diagnostics without exposing exception details.
Code Example
var traceId = HttpContext.TraceIdentifier;
_logger.LogError(
ex,
"Request {TraceId} failed",
traceId);