# async-log

> Utility and sample code for logging async operations in the context of a web-server using the async_hooks core api

Latest version **0.1.0** (published 2017-06-28) · Unlicense license · 0 weekly downloads

## Install

```sh
npm install async-log
pnpm add async-log
yarn add async-log
bun add async-log
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2017-06-28 |
| First published | 2017-06-28 |
| Weekly downloads | 0 |
| License | Unlicense |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=8.1.0 |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Marian COJOC ro |
| Maintainers | marian.cojoc.ro |
| Keywords | nodejs, async, helper, async-hooks |

## Links

- npm: https://www.npmjs.com/package/async-log
- Repository: https://github.com/marian-cojoc-ro/async-log
- Issues: https://github.com/marian-cojoc-ro/async-log/issues
- npm.io page: https://npm.io/package/async-log

## Alternatives

- [lodash.assign](https://npm.io/package/lodash.assign.md) — 2.3M weekly downloads
- [lodash.chunk](https://npm.io/package/lodash.chunk.md) — 1.8M weekly downloads
- [react-native-ios-utilities](https://npm.io/package/react-native-ios-utilities.md) — 138.5K weekly downloads
- [@technically/lodash](https://npm.io/package/@technically/lodash.md) — 50.9K weekly downloads
- [@fluid-topics/ft-icon](https://npm.io/package/@fluid-topics/ft-icon.md) — 20.6K weekly downloads

## Recent versions

- 0.1.0 (latest) — 2017-06-28

## README

# async-log
Utility and sample code for logging async operations in the context of a web-server using the async_hooks core api

# Requirements
* node: > 8.1.0

# Use the helper

(you can view the demo.js file for all the details)

* add it as a dependency
  
  `yarn add async-log`,

* include it in your main entry point

  `const asyncLog = require('async-log');`

* create a transaction every time your server handles a request

  ```
  const trans = asyncLog.newTransaction({
   url: req.url,
  });
   ```

* end the transaction every time your server finished handling the request

  ```
  trans.end();
  ```

* in between these two calls, every time you want to track fetching a remote resource you need to create a new trace before, then end the created trace after

  ```
  const trace = asyncLog.newTrace({ type: 'db' });
  //...
  trace.end();
  ```

# Use the demo

* clone this repo and change directory to it's folder
* start the server in one tab

  ```bash
  node demo.js
  ```

* make request to the server in another tab
  
  ```
  curl http://localhost:3131/ & curl http://localhost:3131/yoyo & wait
  ```

* in the initial tab, you will see how much each request took, and out of that how much it waited for async resources (file access, network requests, etc.)

# Caveats

* the async wait measurements also include some overhead. So it's not 100% accurate. I consider it close enough for my needs.

# Acknowledgements

This is inspired by [this talk](https://youtu.be/A2CqsR_1wyc?t=19587) from [Thomas Watson](https://github.com/watson) and his [example code](https://github.com/watson/talks/tree/master/2016/06%20NodeConf%20Oslo/example-app)

---
_Source: https://npm.io/package/async-log · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
