An open API service indexing awesome lists of open source software.

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.

Awesome Lists containing this project

README

          

# Asynchronous Operations Debugger





npm version
npm downloads


## 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.