Skip to content

Commit

Permalink
Make sure static mdc from withMdc set during actor startup (#29894)
Browse files Browse the repository at this point in the history
* Make sure static mdc from withMdc set during actor startup #29893

* Actually assert mdc is included
  • Loading branch information
johanandren committed Jan 4, 2021
1 parent df46638 commit e8e62e2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e8e62e2

Please sign in to comment.