long-traces
v0.38.0
Published
Adds asynchronous stack traces to error objects.
Maintainers
Readme
Long traces
Adds asynchronous stack traces to error objects.
The long stack is created lazily. The overhead of this module is only adding a property to the error object, when it's thrown.
Installation
npm i long-tracesUsage
import async_hooks from "async_hooks";
import { enable } from "long-traces";
enable(async_hooks);
// stack later in error handling
try {
throw new Error("ups");
} catch (error) {
//this is the stacks of all ancestors (i.e. excluding the errors own stack.)
const longStack = error.getAncestorStackFrames();
}Known issues
- Relies on
__jawisNodeStackset by jacs. So probably only works there. - Has to monkey patch
Errorto get the stack when errors are thrown. This means theinstanceofoperator is not working properly. Might be fixable. - Only works in node because browsers don't have the
async_hooksAPI. This module would work in browsers with such an API available.
Related work
Main inspiration is taken from trace by AndreasMadsen
License
MIT
