How do I implement it in Java?
With the help of the Mapped Diagnostic Context, Javas way to enrich log messages with pieces of information that may not be available in the scope of where the logging actually occurs.
Slf4jMDCFilterConfiguration.java: A configuration file is used to create a FilterRegistrationBean, which handles adding information to our header.
Slf4jMDCFilter.java: A filter to manage adding / creating a correlation id in our MDC and then clean up our MDC when the thread completes.
log4j2.xml: Update your log4j logging pattern to use our new correlation id, using the value - %X{Slf4jMDCFilter.UUID}