I'm dealing with an application using multiple microservices.
The application receieves data and processes it, and I'd like to have a way to monitor everything the received data is going throughout the microservices.
Since the platform is nodejs
we're dealing with asynchronous processing, logs wont always be written one after the other, and since the data does not have aמ ID the logs cannot be filtered in any convenient way.
Is there any way to track the data from the first moment it enters the application till the end, moving between the microservices without having to pass a generate id between all the methods.
Obviously that id will be passed between the microserives but within each one, I'd like to keep the code clean.
I'm using winston
to log, maybe something could fit there.
Thanks in advance, any suggestion would be highly appreciated.
By framework, rsp meant Express, Hapy, Restify, etc. Generically speaking, the idea would be that the service receives the request id in a header (x-request-id). For each request a logger instance is initialised with the id which it will include in any logs.
In your app you need a way of accessing the single logger wherever you want to log from. I would suggest logging only happens in the route handlers so attaching the logger to the request object would likely be the way to go.
Restify handles a lot of this by default. Hapi would need a plugin, and for Express you would use middleware.
You will also then need to ensure that any requests to your other services include the request id header.