Package Exports
- full_stack
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (full_stack) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Full Stack
Stop losing stack trace on Node event loop callbacks.
BEFORE
Error
at Promise.then.x (/home/stefano/repo/full_stack/x.js:8:16)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:169:7)
at Function.Module.runMain (module.js:607:11)
at startup (bootstrap_node.js:158:16)
at bootstrap_node.js:575:3
AFTER
```bash
Error
at Promise.then.x (/home/stefano/repo/full_stack/x.js:8:16)
at
at process._tickCallback (internal/process/next_tick.js:169:7)
at Function.Module.runMain (module.js:607:11)
at startup (bootstrap_node.js:158:16)
at bootstrap_node.js:575:3
at Promise.then
at Array.forEach (native)
at Object.<anonymous> (/home/stefano/repo/full_stack/x.js:7:4)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
at Function.Module.runMain (module.js:605:10)
at startup (bootstrap_node.js:158:16)
at bootstrap_node.js:575:3
This implantation allows all or some event loop callbacks to be intercepted and have its trace stored.
The algorithm is based on **long-stack-traces** (https://github.com/tlrobinson/long-stack-traces) - which I thank!
## 1. Install & import
```bash
npm install -S full_stack
const fullStack = require('full_stack');
2. Setup the traps
fullStack.setDefaultTraps();
You should do this right in the beginning of you code.
This will setup trap on most functions that create event loop tasks.
The default list of traps are:
- Promise.prototype.catch
- Promise.prototype.then
- setTimeout
- setInterval
- setImmediate
- process.nextTick
- EventEmitter.prototypeon (includes http/https/request)
- fs.readFile
- fs.writeFile
But you can set your own trap:
// Eg:
fullStack.trap( Promise.prototype, 'then' );
fullStack.trap( global, 'setInterval' );
fullStack.trap( EventEmmiter.prototype, 'on' );
The function trap
take two argument:
- object {Object}: The object that have the target function/method
- prop {String}: The name of the function/method
3. Enjoy
That's it.
Compatibility
- Node 14.x
- Node 12.x
- Node 10.x
- Node 8.x