MDC propagation via overriding BuiltInComponents.executionContext

34 views
Skip to first unread message

Jeff White

unread,
Jan 16, 2018, 3:25:23 PM1/16/18
to Play Framework
Hoping Greg Methvin and Yann Simon see this...

Per suggestion from Greg in the related thread on MDC propagation via custom Akka dispatcher breaking between play 2.6.9 and 2.6.10, I am making an attempt at the 2nd solution presented in Yann's blog post

Since I use compile-time DI I thought it might be possible to simply override BuiltInComponents.executionContext in my custom ApplicationLoader. I created a minimalist app to demonstrate


It seems to work (though I'm not sure why as DevServerStart creates a separate ActorSystem, also evidenced by the "play-dev-mode" thread names) until I introduce a play-ws call. This causes AsyncHttpClient-named threads to enter the mix, which seems to throw off the propagation. See README.md for sample logs.

Should this approach work, or do I need something more complex?

thanks
jeff



Yann Simon

unread,
Jan 17, 2018, 1:44:49 AM1/17/18
to play-fr...@googlegroups.com
Hi Jeff,

I guess this will work for all computations based on "Future".
It will not work for computations based on akka actors messages, like akka-streams.

You have to be careful to use your custom ExecutionContext everywhere.
I don't remember if it's possible to change the ExecutionContext used by AsyncHttpClient for example.

In general, please have in mind that this is fragile, and do not based on business logic on it.

Cheers,
Yann

--
You received this message because you are subscribed to the Google Groups "Play Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/5089b6ba-8428-449f-92b2-6dec4a9f2d35%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages