To support MDC propagation between threadlocal and reactor operation chain, e.g. using WebClient in Spring MVC, I use a custom ThreadLocalAccessor(from micrometer context-propagation) implementation.
It would be more useful if it is provided by Spring Boot and auto-configures.
Implementation sample from this gist by @chemicL
static class MdcAccessor implements ThreadLocalAccessor<Map<String, String>> {
static final String KEY = "mdc";
@Override
public Object key() {
return KEY;
}
@Override
public Map<String, String> getValue() {
return MDC.getCopyOfContextMap();
}
@Override
public void setValue(Map<String, String> value) {
MDC.setContextMap(value);
}
@Override
public void reset() {
MDC.clear();
}
}
Comment From: wilkinsona
Thanks for the suggestion, @ttddyy. I don't see anything specific to Spring Boot here. Would the code above not be better in Micrometer as has been done with LogbackMetrics? We could then perhaps consider some auto-configuration but I don't think the underlying implementation needs to be a Spring Boot feature.
Comment From: rstoyanchev
I can also see this potentially in the context-propagation library itself in a support package with commonly used ThreadLocalAccessor and/or ContextAccessor implementations that don't have other obvious places to exist.
Comment From: marcingrzejszczak
@chemicL WDYT about adding a SLF4j module in context-propagation library?
Comment From: chemicL
Yep, created: https://github.com/micrometer-metrics/context-propagation/issues/191
Comment From: jonatan-ivanov
I think this issue can be closed in favor of the one in context-propagation (https://github.com/micrometer-metrics/context-propagation/issues/191), we can open an new issue/PR once auto-configuration is needed.
Comment From: ttddyy
closing in favor of https://github.com/micrometer-metrics/context-propagation/issues/191