Skip to content

Include sourceThread in typed actor MDC#3357

Merged
He-Pin merged 1 commit into
apache:mainfrom
He-Pin:fix/3239-typed-mdc-source-thread
Jul 17, 2026
Merged

Include sourceThread in typed actor MDC#3357
He-Pin merged 1 commit into
apache:mainfrom
He-Pin:fix/3239-typed-mdc-source-thread

Conversation

@He-Pin

@He-Pin He-Pin commented Jul 16, 2026

Copy link
Copy Markdown
Member

Motivation

Typed actor logging documents sourceThread as an MDC attribute, but ActorMdc.setMdc did not populate it. This made typed actor log entries inconsistent with classic actors and prevented correlation with the dispatcher thread.

Modification

  • Add the sourceThread MDC entry using the current dispatcher thread name.
  • Add a regression test that verifies the MDC value matches the logging event thread.
  • Update the existing typed MDC whitelist assertion for the documented key.

Result

Typed actor log entries now include the documented sourceThread MDC value, consistent with classic actor logging.

Tests

  • Regression proof without the production MDC.put: focused sourceThread test 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 existing pekko.dispatch.UnboundedMailbox class name in jdocs.stream.IntegrationDocTest.

References

Fixes #3239

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

@pjfanning pjfanning left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@pjfanning pjfanning added this to the 2.0.0-M4 milestone Jul 16, 2026
@He-Pin
He-Pin merged commit 4d821bb into apache:main Jul 17, 2026
10 checks passed
@He-Pin
He-Pin deleted the fix/3239-typed-mdc-source-thread branch July 17, 2026 03:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Typed actor MDC does not include sourceThread

2 participants