Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dontjee/8ffab0fe9e0ef9a8881393fef410f5e0 to your computer and use it in GitHub Desktop.
Save dontjee/8ffab0fe9e0ef9a8881393fef410f5e0 to your computer and use it in GitHub Desktop.
public class CorrelationIdMiddleware
{
private readonly RequestDelegate _next;
public CorrelationIdMiddleware(RequestDelegate next)
{
_next = next ?? throw new ArgumentNullException(nameof(next));
}
public Task Invoke(HttpContext context)
{
if (context.Request.Headers.TryGetValue("X-Correlation-Id", out StringValues correlationId))
{
context.TraceIdentifier = correlationId;
}
return _next(context);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment