scala futures - keeping track of request context w

2019-08-06 05:43发布

making first steps using Scala promises/futures in a web server (still Jetty/synchronous for now :( ), as expected the threadId is no longer useful for tracking what happened during a single HTTP request processing.

I guess logging a request token will do the trick - is this the recommended approach? if so can you refer me to some code already doing that?

2条回答
姐就是有狂的资本
2楼-- · 2019-08-06 05:57

My approach in such situation is to have a case class that holds contextual data (such as request id) and pass it throught all layers of your application as implicit parameter.

查看更多
甜甜的少女心
3楼-- · 2019-08-06 05:57

pardon me for adding an answer, but I just saw this relevant idea published on scala times (http://scalatimes.com/): http://www.schibsted.pl/blog/tracing-back-scala-future-chains/ the gist of it - wrap Future with TraceableFuture which adds the "future stack".

查看更多
登录 后发表回答