Replace cls-hooked with native async_hooks usage
- Dominant language
- JavaScript
- Stars
- 280
- Forks
- 157
- PR merge metrics
- No merged PRs in 30d
Description
This is an odd one, I'm raising it here mostly as a signpost to what's going on for other people hitting it, since it's not really an AWS issue (really, it seems like a rollup or node issue), but possibly there's something this package can do here.
Basically, I use rollup to create my lambda deployment packages, and when I tried adding `aws-xray-sdk-core@3.2.0` it caused the lambda (runtime `nodejs12.x`) to fail with a core dump(!) with the message:
```
/var/lang/bin/node[7]: ../src/async_wrap.cc:308:void node::SetupHooks(const v8::FunctionCallbackInfo&): Assertion `env->async_hooks_init_function().IsEmpty()' failed.
```
If I run the bundled .js file locally with node v14.10.0, I get pretty much the same error:
```
[19312]: c:\ws\src\async_wrap.cc:455: Assertion `env->async_hooks_init_function().IsEmpty()' failed.
```
With some experimenting, I've narrowed it down to simply importing `async-hook-jl`, which is imported by `cls-hooked` when it detects node is less than v8. Due to the way rollup works, this is actually always included and run. I'm not sure if there's a better option, but I got this to work under rollup with the following mini-plugin, which also disables the `pkginfo` module that's throwing under rollup too:
```js
{
name: "exclude-modules",
files: [
"cls-hooked/context-legacy",
"pkginfo",
].map((id) => require.resolve(id)),
load(file) {
if (this.files.includes(file)) {
return { code: "" };
}
},
},
```
Ideally, since node <10 is EOL, it would be nice if the `cls-hooked` dependency could be dropped and the native `async_hooks` module was used directly, or a more modern replacement used, which would avoid this particular headache, but since you've just updated to it to drop node <8 support, I'm guessing that's not likely.
Contributor guide
Assessment
This issue has not been assessed yet.