need some help on logging in nodejs.
In my company, we have several micro-services like cart, orders, payments & also we have lot of internal libs which can also some functions shared between micro-services.
we are following the below pattern in our code base
- routes (defined the routes)
- handlers (here the route handler for all the routes declared)
- managers (this is where business logic lies, these files does not have request / server) - These are pure functions which can be reused even if we change the framework
Let say i create a request-id at server.ext(‘onRequest’) and attach it to request.id to mark every unique requests. Now i can use that reqId logging until handlers alone.
Let also consider in this case i am using pino logger, where every request decorated with request.logger / even hapi has request.log and server.log()
1. Now how can i track the request even in the manager files without passing request / server object.
2. How to track requests between micro-services ?
3. How to track the requests between lib's ?
I have went through cls-hooked
module (using async_hooks) looks like it has memory leaks and increases cpu usage and it is still experimental.
How do you guys manage this in your application ?
Do you pass the requestId as param for every function all along the way to the libraries ?
Aucun commentaire:
Enregistrer un commentaire