Full Stack
Stop losing stack trace on Node event loop callbacks.
BEFORE
Error at Promise.then.x at <anonymous> at process._tickCallback at Function.Module.runMain at startup at bootstrap_node.js:575:3
AFTER
Error at Promise.then.x at <anonymous> at process._tickCallback at Function.Module.runMain at startup at bootstrap_node.js:575:3---------------------------------------- at Promise.then at Array.forEach at Object.<anonymous> at Module._compile at Object.Module._extensions..js at Module.load at tryModuleLoad at Function.Module._load at Function.Module.runMain at startup 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
npm install -S full_stack
const fullStack = ;
2. Setup the traps
fullStack;
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;fullStack;fullStack;
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