Include sourceThread in typed actor MDC#3357
Merged
Merged
Conversation
Motivation: The MDC setup for typed actors (ActorMdc.setMdc) populated pekkoSource, sourceActorSystem, pekkoAddress and pekkoTags, but not sourceThread. Classic actors set sourceThread via Slf4jLogger, and the typed logging documentation already lists sourceThread as an available MDC attribute, so typed actor log entries could not be correlated with the dispatching thread. Modification: Add a sourceThread MDC entry in ActorMdc.setMdc, set to the current thread name. Typed actors log synchronously on the dispatcher thread that runs the actor, so the current thread is the source thread on which the user's log statements execute. Updated the existing MDC whitelist assertion in ActorLoggingSpec to allow the new key and added a regression test asserting sourceThread is present. Result: Typed actor log entries now include sourceThread, consistent with classic actors and the existing documentation. Tests: - sbt "actor-typed-tests/testOnly org.apache.pekko.actor.typed.scaladsl.ActorLoggingSpec" -> 20 passed - Verified the new test fails before the fix (no sourceThread in typed MDC) References: Fixes apache#3239
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Typed actor logging documents
sourceThreadas an MDC attribute, butActorMdc.setMdcdid not populate it. This made typed actor log entries inconsistent with classic actors and prevented correlation with the dispatcher thread.Modification
sourceThreadMDC entry using the current dispatcher thread name.Result
Typed actor log entries now include the documented
sourceThreadMDC value, consistent with classic actor logging.Tests
MDC.put: focusedsourceThreadtest failed as expected because the MDC key was absent.sbt "actor-typed-tests / Test / testOnly org.apache.pekko.actor.typed.scaladsl.ActorLoggingSpec"— 20 passed.sbt "headerCreateAll" "+headerCheckAll" "checkCodeStyle"— passed.sbt "+mimaReportBinaryIssues"— passed for Scala 2.13.18 and 3.3.8.scalafmt --list --mode diff-ref=origin/main— passed with no changed files reported.git diff --check origin/main...HEAD— passed.sbt validatePullRequest— attempted; the changed typed logging suite and affected actor suites passed, but the aggregate task failed on unrelated local/baseline cases: a JDK 25 JFR method-signature mismatch in cluster-sharding Multi-JVM, unavailable LevelDB JNI on macOS ARM in persistence-typed, and the existingpekko.dispatch.UnboundedMailboxclass name injdocs.stream.IntegrationDocTest.References
Fixes #3239