playframework / playframework/playframework

Set log MDC on new Threads

Open
#8,387 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Scala
Stars
12.6k
Forks
4k
Avg merge
2d 3h
Merged PRs (30d)
29

Description

Hi team,

It would be very helpful to have the log MDC copied to new threads, the same way the HttpContext is today.

See:
https://github.com/playframework/playframework/blob/bba57346299581ce7759e91975c16adc0fe15087/framework/src/play/src/main/scala/play/core/j/HttpExecutionContext.scala#L47-L62

This way we can easily keep track logs originated on a specific request. Current the MDC values are lost when using async operations like WS API handleAsync().

It should be a simple change. I can submit a MR if you guys agree with this change.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with framework/src/play/src/main/scala/play/core/j/HttpExecutionContext.scala at the referenced lines, and trace how HttpContext is propagated to new threads. Check how async operations such as WS API handleAsync() create or use execution contexts. Done means MDC values remain available in logs produced by work on those new threads.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
backend, observability
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.