https://github.com/nodesource/ah-stack-capturer
Captures async hook stack traces for specific resource types and events.
https://github.com/nodesource/ah-stack-capturer
Last synced: 10 months ago
JSON representation
Captures async hook stack traces for specific resource types and events.
- Host: GitHub
- URL: https://github.com/nodesource/ah-stack-capturer
- Owner: nodesource
- License: mit
- Created: 2017-01-24T19:36:00.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-02-09T19:00:17.000Z (almost 9 years ago)
- Last Synced: 2025-01-18T13:28:37.877Z (12 months ago)
- Language: JavaScript
- Homepage: https://nodesource.github.io/ah-stack-capturer
- Size: 1.13 MB
- Stars: 1
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ah-stack-capturer [](http://travis-ci.org/nodesource/ah-stack-capturer)
Captures async hook stack traces for specific resource types and events.
```js
const capturer = StackCapturer.forAllEvents()
capturer.shouldCapture('init') // => true
const stack = capturer.captureStack()
const processed = capturer.processStack()
```
## Installation
npm install ah-stack-capturer
## [API](https://nodesource.github.io/ah-stack-capturer)
### StackCapturer
Creates StackCapturere instance.
Either `shouldCapture` OR `events` with optional `types` need to be supplied.
**Parameters**
- `$0` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** configures when a stack should be captured
- `$0.events` **[Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)<[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)>?** defines on which async hooks events
(init|before|after|destroy) a stack should be captured (optional, default `null`)
- `$0.types` **[Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)<[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)>?** defines for which async hook types a
stack should be captured (optional, default `null`)
- `$0.shouldCapture` **[function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)?** `function ((event, type, activity)`
if supplied overrides the `shouldCapture` method entirely (optional, default `null`)
### stackCapturer.shouldCaptureStack
Returns `true|false` indicating if a stack should be captured according to the
options passed in the @constructor.
**Parameters**
- `event` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the async hook event (init|before|after|destroy)
- `type` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the type of async resource that triggered the event
Returns **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** `true` or `false` indicating if a stack should be captured
### stackCapturer.captureStack
Captures the current stack.
Returns **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the current stack
### stackCapturer.processStack
Processes the supplied stack by splitting the string into lines
and removing those that are part of the async hook execution itself.
This allows the user to focus only on the relevant stack.
**Parameters**
- `stack` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the captured stack
Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)>** the processed stack
### StackCapturer.forAllEvents
Creates a StackCapturer that captures ALL events for the supplied types.
**Parameters**
- `types` **[Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)<[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)>?** types passed to the StackCapturer constructor
### StackCapturer.turnedOff
Creates a StackCapturer that captures nothing.
## License
MIT