I am using slf4j in my akka based application and using its MDC feature to log contextual information. I have one base actor who sends and receives messages from a set of actors who in turn communicate and with one other actor and so forth. How do I propagate the MDC setup in the base actor to the other actors ? I would like to avoid using additional frameworks like Play.
Approach 1: Using Receive Pipeline feature of Akka - http://doc.akka.io/docs/akka/2.4.16/contrib/receive-pipeline.html
Sample solution using Receive Pipeline - https://stackoverflow.com/a/39320938/3076069
Approach 2: 1.Creating a trait that extends Actor 2.Override the method aroundReceive to populate MDC 3.Creating new methods for ask_and_forget and send that send a message with mdc and extract it internally
Approach 3: 1. Create a trait that handles MDC on receiving a message and mixin every Actor. (assumes that an incoming message to every Actor will always have the required fields for populating the MDC).
I prefer approach 1 and 3 since they introduce the least breaking changes to the application and appear more intuitive for any new developer that would work on an existing application that uses either of the approaches.