I'd like to propagate X-Request-Id received from my Nginx to other services in my k8s when calling them using http.
Right now, I'm using request filters to catch that X-Request-Id header and putting it to the MDC.
final String nginxRequestId = requestContext.getHeaderString("X-Request-Id");
if (nginxRequestId != null) {
MDC.put("infra_request", nginxRequestId);
}
Now, I'm calling the endpoint of service B inside the k8s (so no Nginx in the way) and I'd like to obtain that X-Request-Id to put it into the request's header. I can see two options here:
- simply get that value from MDC
- store that header in the thread local variable (as the service is using Dropwizard) in addition to storing it in MDC
I'd probably do it using the MDC, but I'm not sure whether this is the best practice or whether there could be some catch/problems with that.