Skip to content

Commit 133d154

Browse files
Add console.createTask section (#13)
Co-authored-by: Justin Ridgewell <[email protected]>
1 parent 7481aa5 commit 133d154

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,8 +483,47 @@ This is what the proposal evolved from. `async_hooks` in Node.js enabled async
483483
resources tracking for APM vendors. On which Node.js also implemented
484484
`AsyncLocalStorage`.
485485

486+
## Chrome Async Stack Tagging API
487+
488+
Frameworks can schedule tasks with their own userland queues. In such case, the
489+
stack trace originated from the framework scheduling logic tells only part of
490+
the story.
491+
492+
```console
493+
Error: Call stack
494+
at someTask (example.js)
495+
at loop (framework.js)
496+
```
497+
498+
The Chrome [Async Stack Tagging API][] introduces a new console method named
499+
`console.createTask()`. The API signature is as follows:
500+
501+
```typescript
502+
interface Console {
503+
createTask(name: string): Task;
504+
}
505+
506+
interface Task {
507+
run<T>(f: () => T): T;
508+
}
509+
```
510+
511+
`console.createTask()` snapshots the call stack into a `Task` record. And each
512+
`Task.run()` restores the saved call stack and append it to newly generated
513+
call stacks.
514+
515+
```console
516+
Error: Call stack
517+
at someTask (example.js)
518+
at loop (framework.js) // <- Task.run
519+
at async someTask // <- Async stack appended
520+
at schedule (framework.js) // <- console.createTask
521+
at businessLogic (example.js)
522+
```
523+
486524
[async stack traces]: https://v8.dev/docs/stack-trace-api#async-stack-traces
487525
[`AsyncResource.runInAsyncScope`]: https://nodejs.org/dist/latest-v14.x/docs/api/async_hooks.html#async_hooks_asyncresource_runinasyncscope_fn_thisarg_args
488526
[Domain Module Postmortem]: https://nodejs.org/en/docs/guides/domain-postmortem/
489527
[SOLUTION.md]: ./SOLUTION.md
490528
[SCOPING.md]: ./SCOPING.md
529+
[Async Stack Tagging API]: https://developer.chrome.com/blog/devtools-modern-web-debugging/#linked-stack-traces

0 commit comments

Comments
 (0)