scala futures - keeping track of request context when threadId is irrelevant

烂漫一生 提交于 2019-12-11 10:26:26

问题


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?


回答1:


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.




回答2:


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".



来源:https://stackoverflow.com/questions/33720563/scala-futures-keeping-track-of-request-context-when-threadid-is-irrelevant

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!