AbhiPrasad
AbhiPrasad•5mo ago

How to access AsyncLocalStorage

Is importing from node:async_hooks the best way to use AsyncLocalStorage with Deno apps? Is there another alternative? Ideally I'd like to update https://github.com/getsentry/sentry-deno to be more aligned with the Sentry Node SDK, but this is a blocker.
GitHub
GitHub - getsentry/sentry-deno: The Official Sentry Deno SDK
The Official Sentry Deno SDK. Contribute to getsentry/sentry-deno development by creating an account on GitHub.
1 Reply
Deno AI Helper
Deno AI Helper•5mo ago
Yes, in Deno, you can access AsyncLocalStorage by importing it from node:async_hooks. The documentation confirms that Deno provides polyfills for a number of built-in Node.js modules and globals, including AsyncLocalStorage. Here's how you can import it:
import { AsyncLocalStorage } from "node:async_hooks";
import { AsyncLocalStorage } from "node:async_hooks";
This should allow you to use AsyncLocalStorage in a way that is similar to how it's used in Node.js applications, which could help in aligning the Sentry Deno SDK with the Sentry Node SDK. 🦕 Remember to check the Node API Compatibility List in the documentation for any nuances or specific details about the current support status when working with Node.js compatibility features in Deno.