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

How to add an optional/custom parameter in the cls-tracer express middleware request #56

Closed Gurpindersingh closed 2 years ago

Gurpindersingh commented 2 years ago

I want to pass an additional optional parameter as username to trace the HTTP request and log the entries. Currently, I am using rTracer.id() of cls-rtracer npm module in my express application to trace the http request. I would really appreciate if someone can help me to pass 'username' as an optional parameter using cls-tracer module.

From React Application, I am passing username in headers and making http request to node.js application. I want to capture username in express application and pass to my outbound service request(Node.js Micro service). In the Node.js Microservice, I want to trace the incoming request and log using Username

puzpuzpuz commented 2 years ago

Hi @Gurpindersingh,

You could use requestIdFactory option to provide a custom object as the id: https://github.com/puzpuzpuz/cls-rtracer#configuration

Gurpindersingh commented 2 years ago

Thanks @puzpuzpuz