Thanks everyone for the feedback!
I'll try to answer all the questions:
@Jaap Taal:
> This looks really great, maybe typesafe could review these kind of things and even port them to play itself. I think these rich contexts are really needed for things like logging etc.
Yes, it would be good if some expert eyes could review this code.
Concerning porting this functionality into play itself, I have mixed feeling:
On one hand, MDC is very convenient very logging.
On the other hand, using a ThreadLocal is a severe limitation of the
default implementation. Managing ThreadLocal variables in asynchronous
context can be quite tricky.
-> Maybe we can open an issue to discuss that on github.
Otherwise, I'd take time to package this code as library.
Anyways, I'm very happy that the play framework is flexible enough to
allow custom ExecutionContext. AFAIK this was not possible with the
first versions. Achieving that was a huge amount of work, especially
in the Iteratee area. Hats off to the team for that!
> How is the performance of this code? Could you show that the overhead is not too big?
I've not performed any scientific measurements. I'd say the
performance overhead is very light.
Actually, a similar custom ExecutionContext is already used for java
projects for the HttpContext:
https://github.com/playframework/playframework/blob/master/framework/src/play/src/main/scala/play/core/j/HttpExecutionContext.scala
@EduP:
Thanks for the pointer!
If any transparent solution works, I'd glad to delete my code.
As far as I can understand the custom MDC in Akka, the values are
applied to the current actor.
They are not propagated from actor to actor.
And they are not propagated if you use a Future with an
ExecutionContext neither.
This is quite limiting IMO.
Or do I understand the Akka custom MDC wrong?
Cheers,
Yann