Add support for .child() on clients with beforeSync and afterSync hooks.#77
Add support for .child() on clients with beforeSync and afterSync hooks.#77joshwilsdon wants to merge 5 commits intorestify:masterfrom joshwilsdon:upstream
Conversation
|
Thank you for the PR, Josh. I'll take a look through the code, documentation and tests. |
lib/HttpClient.js
Outdated
| } | ||
|
|
||
| req.on('result', function _onResult(res_err, res) { | ||
| res.on('end', function () { |
There was a problem hiding this comment.
Do you mind naming this function?
There was a problem hiding this comment.
Not at all. Sorry I missed that one.
1 similar comment
|
I found an issue with this for a use-case where beforeSync and afterSync need to coordinate for an individual request. The issue is that there's no way to pass something from beforeSync to afterSync so that the two know they're related. If you have something like the following: where In order to allow for this sort of use where you want beforeSync and afterSync to share data, I will be adding an additional and it would work the way the caller originally intended. |
1 similar comment
|
Can you look into using continuation local storage to pass context around? On Wednesday, September 28, 2016, Josh Wilsdon notifications@github.com
Via mobile |
|
@yunong: sure, I'll look into that and report back. |
|
Awesome! On Thursday, September 29, 2016, Josh Wilsdon notifications@github.com
Via mobile |
|
@yunong: I've spent some time looking at continuation local storage and I now have a question for you. Was your intention here that we be able to avoid adding the What I looked at was based on this example which demonstrates the original problem: when run that outputs something like: Whereas changing to use the and produces output closer that looks like what one might expect: The same code also works if I swap in so this does work, it just pushes a bit more complexity up to the caller. It also would cause problems for post-mortem debugging, at least the standard Adding So I guess my question boils down to: is there a reason you'd not like to have the |
|
Hey Josh, I'm out of the country at this moment -- mind if we pick this up next week? -Y On 4 October 2016 at 05:06, Josh Wilsdon notifications@github.com wrote:
|
|
@yunong: sure, no problem. |
1 similar comment
|
@yunong: I've been experimenting some more with cls and I really like the idea of using it in the abstract. Thanks for pointing me at that. I'm still working on trying to figure out a way to use it that avoids monkey-patching all of node core and avoids breaking postmortem debugging. I'll continue prototyping and let you know when I have something further for discussion on this PR. |
|
@yunong: Sorry for the delay getting back to you. I've spent more time looking into this and banging my head against it and
This last point means that the only workable solution for either of the current Meanwhile I also spent some time thinking about this implementation and realized In making the change above, I've modified the API so that:
Since this is such a major change over what's in this current PR, I will now If in the future the issues in node are fixed, users will be able to stop |
This change adds support for .child() on HttpClient, StringClient and JsonClient. Child creation takes an object that can have a .beforeSync() and/or .afterSync() function. These functions will be called before and after each request made through the resulting child client. This is especially useful for enabling distributed tracing for restify clients when using a restify server.