4 ms·
This was really great and closely matches how we do it as well. For people who generally follow this approach, what's your take on structured logging transacti
by qxqdtqutwtv 5y ago
This was really great and closely matches how we do it as well.
For people who generally follow this approach, what's your take on structured logging transaction traces, or more generally, propagating request-contextual information through the call stack? TFA seems to prefer a res.locals approach, but it's coupled to the framework in a way that the article avoids elsewhere, and needs manual propagation beyond the express handoff. I've seen these alternatives:
One team in my organization uses explicit context objets that get passed to every function call as the first argument, in a style very similar to what is idiomatic in Golang. I find this to be viral and not to compose well with third-party code that ends up calling your own code, which is rare with npm modules but somewhat common with company-internal libraries.
Another team was an early adopter of node async hooks to create the equivalent of a continuation local storage, with cls-hooked at around the time of node 8. They reported several problems that were implementation related, but seemed to prefer the developer experience of the approach, and context was preserved through third party code just fine.
E: (Apparently this now ships standard in node with AsyncLocalStorage)