tracking request flow by ID in node.js
<p>In my node.js application whenever I get request I'd like to "stamp" it with some unique ID and be able to track all the activities (log statements) related to this request by this ID. So when request comes in and I pass its handing to lower application layers (services, database calls etc) I want to be able to collect all logs matching given request ID to rebuild its journey through the app.</p>

<p>So having this picture, I use <a href="https://github.com/dimichgh/request-local" rel="noreferrer">request-local</a> module now, but it does some heavy magic that has just failed me (logs from multiple requests get the same ID).</p>

<p>The code is mostly based on Promises (not plain old node callbacks) and I use higher order functions to provide dependencies to my actual functions (with application tree being built during the start).</p>

<p>First and quite obvious solution would be to pass this request ID down to every function called, but it's a disaster and I'm not gonna do that. </p>

<p>How do you (reliably) do that kind of request tracking without explicitly passing this id/context as an extra argument to functions all levels down?</p>