npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

superstack

v0.0.4

Published

long stack traces for node.js

Downloads

1,040

Readme

superstack Build Status

long stack traces for node.js over async/io boundaries

install

npm install superstack

use

Just require superstack in your project. Ideally one of the first requires (see how it works for why)

var superstack = require('superstack');

function f () {
    throw new Error('foo');
}
setTimeout(f, Math.random());
setTimeout(f, Math.random());

Your stack traces will now extend beyond async call boundaries. From the code above.

Before superstack

Error: foo
    at f [as _onTimeout] (.../node-superstack/foobar.js:2:11)
    at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)

We have no idea which setTimeout call actually caused the error.

After

Error: foo
    at f (/Users/shtylman/projects/node-superstack/foobar.js:4:11)
    at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)
    at Object.<anonymous> (/Users/shtylman/projects/node-superstack/foobar.js:7:1)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:901:3

Notice that the stacktrace identifies which of the two setTimeout fired first and this caused the error.

options

superstack.empty_frame

By default, the stacktrace appears as one long stacktrace. If you want to see the superstack framing boundaries set this value to a string and it will appear in the callstack.

superstack.async_trace_limit

Set this to a positive number to limit the number of frames superstack will capture. This is how many nested async calls back to report. A values of -1 means unlimited. Default is 10.

superstack.format_stack

Function used by superstack to format the stacktrace string. See the implementation for default. The default conforms to the v8 stacktrace strings.

how it works

Superstack works by intercepting certain node.js EventEmitter, process, and Timer APIs. By intercepting the api call and injecting a wrapper callback, any error can be captured and additional frame information added via Error.prepareStackTrace

The following calls are intercepted.

EventEmitter

  • on/addListener
  • once
  • removeListener
  • listeners

process

  • nextTick
  • _nextDomainTick

globals

  • setTimeout
  • setInterval
  • setImmediate

testing

If you find an instance of usage that is not properly captured, please open an issue and provide a testcase to reproduce.

The usual npm test can be run. A more rigorous set of tests can be run by running the runme.sh script in test/modules. It will clone a few popular node.js repos and run their test suits with superstack enabled. This helps ensure that there are limited side effects.

References

Thanks to mattinsler/longjohn and tlrobinson/long-stack-traces for the ideas and code. Longjohn code is MIT licensed.

Also relevant a pdf on the initial idea of long stack traces via an EventSource.

License

MIT