https://github.com/zero734kr/async-debug
Asynchronous operation debugger built on top of async_hooks, inspired by asyncio debug mode of Python.
https://github.com/zero734kr/async-debug
async async-hooks debug performance tracing
Last synced: 6 months ago
JSON representation
Asynchronous operation debugger built on top of async_hooks, inspired by asyncio debug mode of Python.
- Host: GitHub
- URL: https://github.com/zero734kr/async-debug
- Owner: zero734kr
- License: apache-2.0
- Created: 2022-10-22T20:00:46.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-03-06T06:09:25.000Z (over 3 years ago)
- Last Synced: 2025-12-27T16:19:13.233Z (6 months ago)
- Topics: async, async-hooks, debug, performance, tracing
- Language: TypeScript
- Homepage:
- Size: 305 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Asynchronous Operations Debugger
## About
``async-debug`` is a Node.js module that debugs your asynchronous operations, inspired by [asyncio debug mode](https://docs.python.org/3/library/asyncio-dev.html#debug-mode) of python.
Currently, the only feature of this module is to listen for your asynchronous operations and log them to the console if they take too long to complete (considered "slow").
## Limitation
As async_hooks does not provide information about the execution context, this module cannot provide the detailed location of where the operation was started like Python's asyncio. I will try to find a way to do this in the future. If you have any ideas, please let me know.
## Installation
```sh-session
npm install async-debug
yarn add async-debug
pnpm add async-debug
```
## Usage
```js
import { configure } from "async-debug";
const asyncDebugger = configure({
longTaskThreshold: 250, // 0.25 seconds, default is 300 (0.3 seconds)
})
if (process.env.NODE_ENV === 'development') {
asyncDebugger.enable();
}
// Your code here
// Output:
// Executing asynchronous operation 15 using HTTPCLIENTREQUEST took 313.654224999249ms to complete.
```
And that's it! You can now debug your asynchronous operations.
If you want to setup different thresholds for different operations, you can pass `object` to the ``longTaskThreshold`` parameter like below.
```js
configure({
longTaskThreshold: {
HTTPCLIENTREQUEST: 300,
TCPCONNECTWRAP: 100,
FSREQCALLBACK: 150,
// See https://nodejs.org/api/async_hooks.html#type
}
})
```
### Configuration
All options are described as JSDoc comments, but if I think it's necessary, I'll add them here later.