Lightbend Telemetry supports propagation of the SLF4J Mapped Diagnostic Context (MDC) through Akka actors and Scala Futures. When an MDC is set on the current thread, this will be copied with any subsequent message sends or asynchronous callbacks and reinstated when the receiving actor processes the message or when the callback runs. For example, this allows a request or transaction ID to be set and to appear in all connected log messages.

Cinnamon dependency

First make sure that your build is configured to use the Cinnamon Agent.

To enable SLF4J MDC support, add the following dependency to your build:

libraryDependencies += Cinnamon.library.cinnamonSlf4jMdc
dependencies {
  compile group: 'com.lightbend.cinnamon', name: 'cinnamon-slf4j-mdc_2.11', version: '2.4.2'

No further configuration is required. All actors, including the Akka logging actors and remote actors, and Scala Future callbacks will transport and receive the current MDC. For more information on using the MDC see the Logback MDC documentation.

MDC filter

The MDC keys that get transferred across asynchronous boundries can be filtered using configuration. For example, use the following configuration to only propagate the "id" value:

cinnamon.slf4j.mdc {
  filter = ["id"]

Serialization limit

The MDC is transported along with remote messages. To avoid inadvertently sending a lot of data, there is a limit on the size of the serialized MDC. If the limit is exceeded then the MDC will not be propagated remotely and a warning will be logged. If you reach this limit, you may want to only transport specific keys using the MDC filter configuration, or the limit can be increased. For example, you can use the following configuration to set a different limit:

cinnamon.slf4j.mdc {
  serialization.limit = 2048 bytes