What's a good snippet to safely instrument “almost all functions” using stacktrace.js?

stacktrace.js is a micro-library for getting stack traces in all web browsers.

It offers functions instrumentation:

  • Jasmine expect toThrow not passing nor catching
  • Why would an exception cause resource leaks in Node.js?
  • Javascript exception stack trace
  • Throwing custom exceptions in Javascript. Which style to use?
  • Angular 2 Doesn't Update View After Exception Is Thrown
  • Catching a custom javascript exception with window.onerror - in IE
  • var p = new printStackTrace.implementation();
    p.instrumentFunction(this, 'baz', logStackTrace);
    function logStackTrace(stack) {
        console.log(stack.join(' -> '));
    function foo() {
        var a = 1;
    function bar() {
    foo(); //Will log a stacktrace when 'baz()' is called containing 'foo()'!
    p.deinstrumentFunction(this, 'baz'); //Remove function instrumentation

    What’s the best way to “instrument all or almost all functions” in a safe way?
    Basically I want (say … in “debug mode”) to “auto-catch and log” all stack traces from all functions that are feasible to instrument. What’s a good snippet to do this? Which functions should I avoid instrumenting?

  • alias to chrome console.log
  • Firefox doesn't show custom error messages
  • How do I translate stack traces from Browserify bundles to the original source code positions?
  • window.toString.call is undefined in IE8
  • IE8 developer tools debugger gives wrong exception information
  • What could cause an UmbrellaException anonymous function on deployed GWT app?