How to see order of distributed events in local Node.js dockerised microservice set up?

15 views Asked by At

I have locally few services that run Node.js applications in docker containers.

Flow looks like this:

enter image description here

Basically if service B is doing work and it wrote down in DB that computations S is handled, other request should not be able to get S result data ( as it's not there ).

How can I know the order of events and some metadata associated with them (like - service B set status of S to started and it was prior to second thread of service A wants to get S result data for other request)?

I was thinking about centralised logging, but some events/distributed event tracing may do the trick as well. Simpler - the better.

Solution should use only my local machine, can be some Docker images with some applications - but not payed cloud services.

1

There are 1 answers

0
zmii On

I've used fs.appendFile to get desired outcome ( using macOS ).

Created recordLog.service.ts in code where it's accessible by all places where events should be captured:

import {appendFile} from 'fs';

const fileName = './centralized.log';

export const recordLog = async (message: string, serviceName: string, entityId: string | number) => {
  const timestamp = new Date().toISOString();
  const logMsg = `${timestamp} [${serviceName}] [${entityId}] ${message}\n`;

  appendFile(fileName, logMsg, {flag: 'a'}, () => {});
}