2
votes

I want to introduce effective logging with in my Spring Integration implementation. I already have global wire-tap which logs the payload and headers. However we have lots service activators which has lots of business logic. I want to log important information like user id, request id in every log. We are using SLF4J. The spring integration flow has number of thread pool executors which are managed by Spring integration.

Should I go for AOP where before every method call, I retrieve the userid and request id from message headers and set it in SLF4J MDC? and then clear it once the method execution is over. It would have clearing logic in finally block. Is this a right approach or this would create performance bottle neck? Not sure why this has not been discussed much as in multithreaded SI flow, it would become very difficult to debug logs without user information.

If there is a better approach, please suggest.

1

1 Answers

1
votes

See the SecurityContextPropagationChannelInterceptor introduced in 4.2.

Notice that it is a subclass of ThreadStatePropagationChannelInterceptor.

You could use a similar technique to propagate/clean up the MDC when a message is passed off to another thread. It would be less overhead than doing it on every call made by that thread.

Notice how the information to be propagated is wrapped in a lightweight message wrapper, along with the message. You could also store the information in message headers.

If you come up with a generic implementation, consider contributing it to the framework.