-
Notifications
You must be signed in to change notification settings - Fork 385
Description
Although LLRT implements the async_hooks module, it does not expose AsyncLocalStorage.
https://nodejs.org/api/async_context.html#class-asynclocalstorage
It seems that several well-known packages have adopted or are considering adopting it, so if it is implemented in LLRT, I think it will be able to accommodate new use cases.
Some packages that already use it include:
- hono/context-storage: https://github.com/honojs/hono/blob/main/src/middleware/context-storage/index.ts
- @opentelemetry/context-async-hooks : https://github.com/open-telemetry/opentelemetry-js/blob/main/packages/opentelemetry-context-async-hooks/src/AsyncLocalStorageContextManager.ts
Information on the packages we plan to adopt is as follows:
aws-powertools/powertools-lambda-typescript#2050 (comment)
Additionally, I'd encourage LLRT to add support for
AsyncLocalStoragefromasync_hooks; even for Logger & Metrics (core utilities) we'll most likely start using this API in the next couple months to allow for future use cases.There's even a new package called
@aws/lambda-invoke-store(repo) that, quoting its readme "is designed to be integrated with the AWS Lambda Node.js Runtime Interface Client (RIC)", which means applications targeting versions of Node.js managed runtimes that use this package, might rely onAsyncLocalStorageand not work on LLRT.
Additionally, InvokeStore imported via @aws/lambda-invoke-store should be exposed as globalThis.awslambda.InvokeStore.