diff --git a/akka-actor-typed-tests/src/test/scala/akka/actor/typed/scaladsl/ActorLoggingSpec.scala b/akka-actor-typed-tests/src/test/scala/akka/actor/typed/scaladsl/ActorLoggingSpec.scala index 1cef1367b3..4d37edee07 100644 --- a/akka-actor-typed-tests/src/test/scala/akka/actor/typed/scaladsl/ActorLoggingSpec.scala +++ b/akka-actor-typed-tests/src/test/scala/akka/actor/typed/scaladsl/ActorLoggingSpec.scala @@ -329,7 +329,7 @@ class ActorLoggingSpec extends ScalaTestWithActorTestKit(""" "provide the MDC values in the log" in { val behaviors = Behaviors.withMdc[Protocol]( Map("static" -> "1"), - // FIXME why u no infer the type here Scala?? + // why u no infer the type here Scala?? (message: Protocol) => if (message.transactionId == 1) Map("txId" -> message.transactionId.toString, "first" -> "true") @@ -348,7 +348,9 @@ class ActorLoggingSpec extends ScalaTestWithActorTestKit(""" .info("Starting") // not counting for example "akkaSource", but it shouldn't have any other entries .withCustom(logEvent => - logEvent.mdc.keysIterator.forall(entry => entry.startsWith("akka") || entry == "sourceActorSystem")) + logEvent.mdc.keysIterator.forall(entry => + entry.startsWith("akka") || entry == "sourceActorSystem" || entry == "static") && + logEvent.mdc("static") == "1") .expect { spawn(behaviors) } diff --git a/akka-actor-typed/src/main/scala/akka/actor/typed/internal/WithMdcBehaviorInterceptor.scala b/akka-actor-typed/src/main/scala/akka/actor/typed/internal/WithMdcBehaviorInterceptor.scala index 76effd7d69..633136318a 100644 --- a/akka-actor-typed/src/main/scala/akka/actor/typed/internal/WithMdcBehaviorInterceptor.scala +++ b/akka-actor-typed/src/main/scala/akka/actor/typed/internal/WithMdcBehaviorInterceptor.scala @@ -62,8 +62,12 @@ import akka.annotation.InternalApi case b => b } } - - loop(target.start(ctx)) + try { + setMdcValues(Map.empty) + loop(target.start(ctx)) + } finally { + MDC.clear() + } } // in the normal case, a new withMDC replaces the previous one