Skip to content

ThreadLocalAccessor implementation for MDC #39299

@ttddyy

Description

@ttddyy

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();
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    for: external-projectFor an external project and not something we can fixstatus: supersededAn issue that has been superseded by another

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions