ThreadLocal-like class that keeps its value through Future.map/Future.flatMap is extremely useful to trace request, for example, for logging.
Is there existing abstraction in Scala library to serve as such Local?
Is there a way to attach such Local to ExecutionContext.global?
Here is a blog entry where someone describes using
scala.util.DynamicVariable
and a customscala.concurrent.ExecutionContext
to capture and manage it: http://stevenskelton.ca/threadlocal-variables-scala-futures/And here's is another blog entry describing how Hootsuite does something similar: http://code.hootsuite.com/logging-contextual-info-in-an-asynchronous-scala-application/