Does it work with koa?
xray-sdk itself just provides a way to communicate with xray agent by sending custom segement data. all the helpers like aws / postgres / express are simply an wrappers around it. currently there is no plugin for koa, but i believe writing one as koa middleware would be totally possible. checkout express implementation
@breath103 i added a PR here https://github.com/aws/aws-xray-sdk-node/pull/5
I just take a look at Express implementation and adapt it for koa. Can you help reviewing it?
@tuananh
I am unfamiliar with Koa, so bear with me.
Briefly reading up, Koa seems to rely on async/await as it's primary mechanism to remove use of callbacks. The core package relies on CLS (https://github.com/othiym23/node-continuation-local-storage) for segment propagation, which is reportedly not compatible with async/await (https://github.com/othiym23/node-continuation-local-storage/issues/124).
Have you tested this with a small sized sample application? I think you may run into issues with the segment being lost on an attempt to call getSegment within a series of next calls, as it will not be able to rely on the same automatic propagation mechanism that Express implements (https://github.com/aws/aws-xray-sdk-node/pull/5/files#diff-8e90b35ef034fd32dd73e9dddc9c3730R59).
If this is the case, you may need to either force the SDK into manual mode with a warning message or throw an error when attempting to use it in automatic mode (as the SDK uses automatic mode by default).
Thanks. I will test and get back to you.
Hey @tuananh, you have some update on this test?
Is some work being done to address this or manually segmenting on frameworks using async/await is still the way to go? I see that cls-hooked seem to help in the use cases attached to library promises or async/await. Are there any plans to consider this?
https://github.com/othiym23/node-continuation-local-storage/issues/133.
EDIT: I did see the conversation at #12 , but didn't find a concrete update.
Hi aga5tya,
We have been planning for some experimentation with the cls-hooked library, hopefully soon. From other user reports, it seems to be the right solution. We will be sure to update as soon as we have some findings.
Some related topic on this framework support https://github.com/aws/aws-xray-sdk-node/issues/60
Any update on this? @awssandra It's been over 1y
Hi @sbe-arg,
Thanks for posting this question. We are waiting on 3.0 major release which should fix context propagation issue to support Koa. We still have to prioritize additional testing efforts. Meanwhile we really encourage community to do experimentation and help us gather more data points. We are open to PRs!
Hey all, there is a Koa Middleware project that hadn't gotten any love in a while. I messaged the owner and no response, so I forked it and got it mostly up to speed and it seems to work in my limited testing.
https://www.npmjs.com/package/koa-xray
https://github.com/unbill/aws-xray-sdk-koa
I can pr this into the AWS project, but my referenced packages are a bit newer than some old ones used in this project. Ideally with lerna you'd want them to all be on the same versions.
We also have a hapi-xray library that might be a good candidate for merging into this repo.
https://www.npmjs.com/package/hapi-xray
https://github.com/moonthug/hapi-xray
As well a mongoose-xray library.
https://www.npmjs.com/package/mongoose-xray
https://github.com/unbill/mongoose-xray#readme
I think my main concern would be to get the library references updated to more recent versions. I'm mainly referring to dev tools (eslint/mocha/chai/sinon/etc...)
Hi @eric-swann-q2,
Thank you very much for your contribution, we will be taking a look at your PR shortly! For other libraries, we will have to be careful about adding official support for every framework under the sun since we might not be able to provide quality help to our customers with them without overburdening the maintainers. I'll update the PR once we've decided the best course of action.
Hey @willarmiros, I agree with your general premise, you don't want every possible node framework in here, it's just too much. In the cases of Koa, Hapi, and Mongoose, it's not a biggee to keep them separate, but they are three of the most popular frameworks in the node ecosystem, so it might make sense to pull them in. I think with those in place, you've got all the big rest frameworks and all the big data access frameworks.
cross linking with issue https://github.com/aws/aws-xray-sdk-node/issues/322 while waiting for official answer?
Official support for Koa has been released in the package aws-xray-sdk-koa2 in version 3.2.0! Feel free to leave feedback. I'll be closing this feature request.
Most helpful comment
Hi @sbe-arg,
Thanks for posting this question. We are waiting on 3.0 major release which should fix context propagation issue to support Koa. We still have to prioritize additional testing efforts. Meanwhile we really encourage community to do experimentation and help us gather more data points. We are open to PRs!