puzpuzpuz / cls-rtracer

Request Tracer - CLS-based request id generation for Express, Fastify, Koa and Hapi, batteries included
MIT License
311 stars 24 forks source link

add Additional information along with requestId #68

Closed softmantk closed 1 year ago

softmantk commented 1 year ago

Hi, this question might be wrong but I want to customise the cls-rtracer with additional feature.

Along with requestId, I also want to pass a custom header value and retrieve it later and may be used in my logger to log the info. with requestIdFactory I could set a requestId. is it possible to save additional information in the same context, let's say some sessionId? In our application, both are different. Sometimes sessionId might not exist. storing requestId+sessionId as requestId seems not a solution rather feels like a hack.

puzpuzpuz commented 1 year ago

requestIdFactory supports returning any custom primitive value or object. The idea is that whatever you return from it can be later accessed with a rTracer.id() call, so you can store any object with arbitrary fields there and, maybe, even mutate it at a later point.

puzpuzpuz commented 1 year ago

Closing this one as the readme is now updated accordingly.