I recently added nestjs-cls to add more info to the logs, but ideally the RMQ microservices we have would keep the CLS from where it was originally triggered through ClientProxy emit.
For reference:
`
// microservice connection setup
app.connectMicroservice({
transport: Transport.RMQ,
options: {
urls: [rabbitMqUrl],
queue: queue.name,
noAck: false,
queueOptions: {
durable: true,
prefetchCount: queue.prefetchCount,
},
},
});
// some service called through a http request
this.log('log from service. this log will show some CLS values');
this._someRmqQueue.emit(
'some-message-pattern',
{
foo: foo,
bar: bar,
},
);
// microservice controller
@MessagePattern('some-message-pattern')
async startArtworkProcessingHandler(
@Payload() payload,
@Ctx() ctx: RmqContext,
) {
// ideally this log here would still be able to access the original CLS from above
this.log('log from microservice. ideally the CLS values would be the same as in the service above.');`
I know it would be possible to just pass what I need through the payload, but ideally there would be some solution that doesn't require that manual work each time we publish a message to the queue.
Any ideas? I don't think something like nestjs-cls/transactional is needed. If somehow we can just intercept the emission, we could dynamically add it to the payload (or as a header option using RmqRecordBuilder), even.