How to pass CorrelationId as parameter to any subsequent enqueued job

Hi, guys.

I want to know which endpoint requested a job (especially in logging).
For that purpose, I want to utilize the CorrelationId string taken from HttpContext.TraceIdentifier. The obvious solution is to manually pass the string via method arguments, but I would like to have it in an elegant way. Then, I would like to pass the string via DI injection when a command is created.

Is there a way to automatically retrieve IHttpContextAccessor and use its HttpContext to populate CorrelationId when the job is enqueued?

Hey Artem, I am dealing with the same issue — trying to pass ‘HttpContext.TraceIdentifier’ (CorrelationId) to hangfire jobs for logging. Did you find a clean way to inject IHttpContextAccessor or handle this automatically?

Curious to hear how you solved it.