-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Making it possible to add custom request properties to CLS namespace. #25
Conversation
IMHO, it's better to keep things simple and have a library do one thing, but do it well. I would suggest to create and apply another middleware together with |
@marciopd thanks for your contribution. I see why you need it and understand your use case. Let me think a bit about this feature and whether it fits the |
@marciopd The main blocker for me is that So, I propose to do the following changes in options: useHeader = false, // this option works only when idGenerator is not used
// ...
idGenerator = undefined // new option (function) When used, (req) => { // accepts native request object (from 'http' module)
const id = // generates an id (any type)
return id; // returns it
} Thus, when I'd appreciate if you could change your PR in the described way. WDYT? |
Hi, sounds good. But my use case is mostly about being able to add other request related variables into the same CLS context. For instance, I would like to have the client's IP. So for my use case, maybe instead of exposing directly the What do you think? |
I'd rather keep |
Ok, fair enough. Thanks for your time and the quick replies! Best regards |
I didn't make it clear, probably, but In any case, if you don't have the time to change this PR or submit another one, feel free to open a feature request issue. I may find some time to implement it in the nearest future. |
@puzpuzpuz I could do it. Just to double-check if I got it right, the use case you guys were referring is something like: "As a client of Is that it? |
Yes, that's right. Thanks in advance! |
Hello @puzpuzpuz I have some time to work on this now. Is it still relevant? I saw a related PR which seems to be related (#47). |
@marciopd the main part of this feature was delivered in v2.4.0 (#40), yet the supported signature of factory function is |
Yes, that's exactly what I need. Ok, then I'll pick it up during the weekend. Thx! |
Hi,
It would be awesome to add custom request properties into the CLS namespace, besides the request ID header.
This PR makes it possible by adding a new option to the middleware, a custom namespace properties builder function. This function receives the current request and CLS namespace variable so that client code can add any needed new properties based on the request.
If you like the idea, please feel free to make any changes in the PR.
I'm looking forward to use this new feature, otherwise I'll need to implement again 🙈 .
Best regards!