<p dir="auto">My apologies if this is the wrong venue. It wasn't clear from the contributors guidelines whether issues are a suitable place for questions/feature-requests, and when I asked via <a href="https://discordapp.com/channels/684898665143206084/689420767620104201/725083870164287540" rel="nofollow">the community chat room</a> and the <a href="https://stackoverflow.com/questions/62544235/does-deno-have-a-way-to-track-async-contexts" rel="nofollow">usual places</a> I didn't get much engagement.</p>
<p dir="auto">Does Deno have a supported-or-experimental way to track the creation of asynchronous contexts? I <a href="https://github.com/denoland/deno/issues/945" data-hovercard-type="issue" data-hovercard-url="/denoland/deno/issues/945/hovercard">see async_hooks</a> isn't something you'll be implementing -- at least until <a href="https://github.com/denoland/deno/blob/d16337cc9c59732fe81655482e08b72d844472e6/std/node/README.md">Node lands a non-experimental version of it</a>.</p>
<p dir="auto">The specific use-case I have in mind is <a href="https://www.npmjs.com/package/@opentelemetry/context-async-hooks" rel="nofollow">an OpenTelementry context manager</a>, but I'm also thinking of other Application Performance Monitoring use-cases where we're trying to tie multiple asynchronous actions to a single scope (scope meaning a single HTTP request, or a single GRPC method invocation, etc.)</p>
<p dir="auto">Also, FWIW, the usual cowboy way APM vendors would handle this doesn't look like it's possible in Deno -- redefining the global <code class="notranslate">Promise</code> doesn't carry over when you <code class="notranslate">import</code> other modules. Probably "the right" behavior, but it does seem to make our usual monkey patching not possible.</p>
<p dir="auto">Is this something that's on the roadmap and/or people's minds? "No" is a perfectly acceptable answer, I'm just trying to get the lay of the land before I go down one particular road or the other.</p>
<p dir="auto">Hey,</p>
<p dir="auto">One of the features Node uses from V8 is promise hooks and in particular Node's <a href="https://nodejs.org/api/async_hooks.html" rel="nofollow">async_hooks</a> lets users keep context enabling a lot of use cases (like APMs).</p>
<p dir="auto">I saw <a href="https://github.com/denoland/deno/issues/945" data-hovercard-type="issue" data-hovercard-url="/denoland/deno/issues/945/hovercard">the last issue</a> but it doesn't look like there was a lot of discussion there. As far as I'm aware there is no analogy in the DOM/browser world for this. When I talked to some tooling people in browser vendors they said they were not aware of a direct analogy.</p>
<p dir="auto">I would recommend (barring actual discussions with APM vendors or telling users to use a user promise library and instrumenting its scheduler):</p>
<ul dir="auto">
<li>Exposing SetPromiseHook pretty directly and letting users and vendors deal with it.</li>
<li>Exposing an async_hooks like API - possibly based on Zones (or hopefully another web proposal).</li>
<li>Exposing <em>only</em> the node async hooks API under std/node.</li>
<li>Wait for vendors and complain and not solve it until APM vendors or users complain (then use their feedback to pick an API).</li>
<li>Something else entirely.</li>
</ul>
<p dir="auto">It's true async_hooks are experimental and domains are deprecated but without neither - it is pretty impossible to build an APM for Node. You have to instrument methods to know "where you came from" in an async context and APMs are pretty valuable tools.</p>