You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@pekko.apache.org by "He-Pin (via GitHub)" <gi...@apache.org> on 2026/06/27 21:57:45 UTC

[I] Typed actors do not set sourceThread MDC value [pekko]

He-Pin opened a new issue, #3231:
URL: https://github.com/apache/pekko/issues/3231

   ### Motivation
   The typed actor logging documentation explicitly states that `sourceThread` should be available in MDC, but the implementation does not set this value. This creates a documentation/implementation mismatch that affects users who rely on the documented behavior to identify which thread an actor was running on when logging.
   
   ### Current behavior
   In `actor-typed/src/main/scala/org/apache/pekko/actor/typed/internal/ActorMdc.scala:29-38`, the `setMdc` method only sets four MDC values:
   - `pekkoSource`
   - `sourceActorSystem`  
   - `pekkoAddress`
   - `pekkoTags` (conditional)
   
   The `sourceThread` MDC value is never set, despite being documented.
   
   ### Expected behavior
   The `setMdc` method should also set `sourceThread` with `Thread.currentThread().getName`, matching the behavior of the classic `Slf4jLogger` which sets this value at `slf4j/src/main/scala/org/apache/pekko/event/slf4j/Slf4jLogger.scala:134`.
   
   The documentation at `docs/src/main/paradox/typed/logging.md:412-413` states:
   > "Since the logging is done asynchronously, the thread in which the logging was performed is captured in MDC with attribute name `sourceThread`."
   
   ### Code evidence
   **Missing implementation:**
   - `actor-typed/src/main/scala/org/apache/pekko/actor/typed/internal/ActorMdc.scala:29-38` - `setMdc` does not set `sourceThread`
   
   **Working reference (classic logger):**
   - `slf4j/src/main/scala/org/apache/pekko/event/slf4j/Slf4jLogger.scala:134` - `MDC.put(mdcThreadAttributeName, logEvent.thread.getName)`
   
   **Documentation promise:**
   - `docs/src/main/paradox/typed/logging.md:412-413` - explicitly states `sourceThread` is available
   
   **Missing test coverage:**
   - `actor-typed-tests/src/test/scala/org/apache/pekko/actor/typed/scaladsl/ActorLoggingSpec.scala:500-506` - `assertExpectedMdc` only checks for `pekkoAddress`, `pekkoSource`, and `sourceActorSystem`, not `sourceThread`
   
   ### Reproduction
   1. Create a typed actor that logs a message
   2. Configure logback to include `%X{sourceThread}` in the pattern
   3. Observe that `sourceThread` is empty/missing in the log output
   4. Compare with a classic actor where `sourceThread` is correctly populated
   
   Example test case:
   ```scala
   Behaviors.setup[String] { context =>
     context.log.info("test")
     val thread = MDC.get("sourceThread")
     // Expected: thread should be non-null and contain the actor's thread name
     // Actual: thread is null
     Behaviors.empty
   }
   ```
   
   ### Impact
   - **Module:** pekko-actor-typed
   - **Affected users:** All users of typed actors who rely on MDC for structured logging and expect `sourceThread` to be available as documented
   - **Use cases affected:** Log analysis, debugging, and monitoring that depend on knowing which thread an actor was executing on when logging
   - **Consistency:** Creates inconsistency between classic and typed actor logging behavior


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [I] Typed actors do not set sourceThread MDC value [pekko]

Posted by "He-Pin (via GitHub)" <gi...@apache.org>.
He-Pin closed issue #3231: Typed actors do not set sourceThread MDC value
URL: https://github.com/apache/pekko/issues/3231


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [I] Typed actors do not set sourceThread MDC value [pekko]

Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on issue #3231:
URL: https://github.com/apache/pekko/issues/3231#issuecomment-4828029271

   duplicated by #3239 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org