-
Notifications
You must be signed in to change notification settings - Fork 98
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
Support hapi@17 #601
Comments
@kjin anything I can do to help with this effort? |
@BenCrux Yes! A PR would be greatly appreciated. The Hapi tracing plugin currently goes up to 16. As hapi 17 types aren't released yet (tracking issue), you can modify The relevant unit tests are a little bit in flux so don't worry about them for now -- I'll update this issue when the new unit tests for web frameworks are landed. edit: I'm working on this now (2018-02-20) |
Thanks @kjin! I started looking at this and do have it working in a handcrafted way. One thing that I had to do was change the AsyncHooksNamespace (cls-ah.js) not to reset 'current' in runAndReturn. I didn't really understand why it was doing that. Since runAndReturn is used in the runInRootSpan and that's when the root span is saved to cls, so it never gets persisted and you can never create child spans (because the root span can't be found). What am I missing here? |
Great! I've actually started work to change the plugin system to allows multiple plugins for a single module, which should help (because that way we can use different type definitions for different plugins). It's true that the root span is associated with I'm more than happy to dive into more details if you need -- since I'm not sure how familiar you are with If it helps, while working on it feel free to modify |
Ah ok - makes sense, thanks! I think the problem I'm butting up against is that I'm using a lifecycle method in hapi; |
If I understand the lifecycle flow in Hapi correctly, what you're saying is that you'd be specifying multiple handlers for a single request, and the handler in which asynchronous work is being done may not be in the The existing model for ending root spans is to find the raw As for starting async work outside of the |
Yes that's correct. It's my understanding that the |
You can store a bound function on the const assert = require('assert');
const trace = require('@google-cloud/trace-agent').start();
const kBind = Symbol();
function preWork(request) {
trace.runInRootSpan({ name: 'parent' }, (span) => {
request[kBind] = trace.wrap(fn => trace.wrap(fn));
});
}
const request = {};
preWork(request);
const work = request[kBind](() => {
const span = trace.createChildSpan({ name: 'child' });
console.log(span); // not null
});
work(); This might seem a bit of a hack, but I believe it may only be possible to do away with storing an extra property on the request object if we're monkeypatching at a lower level where the request object is actually being passed to these functions (just a thought -- it might not be worth the extra brittleness of doing so) |
Hi @BenCrux, do you have an update on this? If you've been busy but have any partial work done I'd be happy to take it from there 😁 |
Hi @kjin - yeah we got it I think working, happy to share what we did - I'm not sure it's 100% correct. We are basically monkey patching the hander.execute method in a hapi plugin:
Would be great to get your feedback on the correctness of this etc. We think we might be miss-attributing sub-traces sometimes. |
@BenCrux would you mind opening a PR with what you have? We can add onto the PR, but having a PR will ensure that the commit gets credited back to you and also to ensure we have the right CLAs in place to accept your contribution. |
@ofrobots so this is just a hapi plugin we wrote and then inject into the server, so it doesn't really fit into the existing code base anywhere (I think?); it's also not typescript. If you give me a directory to check this file in, then happy do to that - although we don't care about attribution, most of this is a copy of the existing code with some minor tweaks. |
Hapi 17 tracing support has been officially added in 2.7.0. Please file a new issue if there are any problems with it! Important You'll need to enable async_hooks tracing with env var /cc @BenCrux |
This issue tracks support for hapi 17 tracing.
The text was updated successfully, but these errors were encountered: