[slf4j-dev] MDC works with twitter scala Future but not CompletableFuture

Dean Hiller dhiller at twitter.com
Thu Mar 22 14:51:57 CET 2018


Has anyone requested the jdk to add Local.java to CompletableFuture.java so
that context can be transferred through the .thenApply and .thenCompose
methods.  ie. can we make MDC work in java-land with CompletableFutures?
(it works in scala land with twitter scala Future by swapping the MDC out
for the below thing I describe)

let me go into more detail here.  We use twitter Future.scala which knows
about Local.scala and Local.scala "acts" like a ThreadLocal.  I say acts
because when you do future.map/flatMap(in java that is
thenApply/thenCompose), it transfers the threadlocal through to the next
executing function.

soooo, long story short, in twitter servers, I can say MDC.put("requestId",
someRequestId) and it works over the .map/.flatMap.  This is not possible
in java!!!!! ahhhhh....

and I wrote a whole webserver in java with CompletableFutures before I
found this out https://github.com/deanhiller/webpieces

ps. their response was that it would be a global.  Sure, but I am practical
and it solves a huge many platform problems like MDC, and some in my server
where I don't know the customers code(and I had to hack around not having a
Local type thing available :( ).

Another reason they elude to is some methods they don't know how to handle
Local in those cases(yup, well scala had the same thing but it managed to
implement it because it was too important and now java is behind :( ).

Anyways, it would be nice if others spoke up before they realize they need
it for the MDC to keep working.

thanks,
Dean
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/slf4j-dev/attachments/20180322/10cc6665/attachment.html>


More information about the slf4j-dev mailing list