Our application utilizes message metadata in the mapped diagnostic context (MDC) of the logging framework. Currently, we have ad-hoc MessageHandlerInterceptors set up to manage the add/remove of metadata to/from the SLF4J MDC. However, there is some utility to having this as the default behavior of the application. Furthermore, the interceptors may place an incorrect data value on the MDC when nested units of work are present.
I created a pull request on the AxonFramework to manage this process in the CurrentUnitOfWork class. This seemed appropriate because the metadata can be added and removed as needed when multiple units of work are in progress. However, in order to provide more fine-grained control, such as disabling this feature in configuration or stipulating metadata keys that cannot be logged, more information would need to be added to the UnitOfWork interface or AbstractUnitOfWork class.
The pull request can be found here: https://github.com/AxonFramework/AxonFramework/pull/512