Make sure static mdc from withMdc set during actor startup (#29894)

* Make sure static mdc from withMdc set during actor startup #29893

* Actually assert mdc is included
This commit is contained in:
Johan Andrén 2021-01-04 15:04:14 +01:00 committed by GitHub
parent df4663867d
commit e8e62e2ca2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 4 deletions

View file

@ -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)
}

View file

@ -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