3 ms·
Not so obvious. How to implement it without passing request id to all the functions, when they are unrelated to request/http ? Especially in languages without t
by janci 4y ago
Not so obvious. How to implement it without passing request id to all the functions, when they are unrelated to request/http ? Especially in languages without thread-locals such as javascript?
- gh123man 4y agoMany frameworks solve this with logger context. Add the properties you want to the logging context and all future logs in that context will have that property. One simple example - Serilog enrichment https://github.com/serilog/serilog/wiki/Enrichment https://github.com/serilog/serilog/wiki/Enrichment This does however assume your entire application uses the same logger. But this is generally a requirement in services that require tracing like this.
- yakshaving_jgt 4y agoYou can stick it in a middleware which wraps the request lifecycle.
- mrloba 4y agoNodejs now has async local storage built in, which makes this fairly easy.
- veyh 4y agoFor example: https://github.com/puzpuzpuz/cls-rtracer https://github.com/puzpuzpuz/cls-rtracer