Skip to content

Instantly share code, notes, and snippets.

@andrewtamura
Last active May 10, 2017 18:26
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewtamura/61d32b1b1ea9e98c5e15cb833243d755 to your computer and use it in GitHub Desktop.
Save andrewtamura/61d32b1b1ea9e98c5e15cb833243d755 to your computer and use it in GitHub Desktop.
raven wrapper with monkey patch for local logging
var Raven = require('raven');
// Configure the Raven client from the Sentry DSN. For local development, keep this environment variable unset to prevent
// Raven from sending events to sentry
var ravenClient = new Raven.Client(configOptions);
var originalCaptureException = ravenClient.captureException;
// Monkey patch the captureException function for easier development flow.
ravenClient.captureException = function() {
// this._enabled is true if SENTRY_DSN is set. When developing locally, unset this environment variable.
if (!this._enabled) {
// the first parameter to captureException is the Error object.
var err = arguments[0];
console.error(err.stack || err);
} else {
originalCaptureException.apply(this, arguments);
}
}
// Return the configured Raven client
module.exports = ravenClient;
@Caerbannog
Copy link

Note that you should probably replace this line:

    originalCaptureException.apply(this, arguments);

with this line:

    return originalCaptureException.apply(this, arguments);

Compare the two outputs:

raven@1.2.1 alert: uncaughtException: undefined
raven@1.2.1 alert: uncaughtException: 990b6d61111b25fb9dd77302cc24119e

@d3v2a
Copy link

d3v2a commented May 10, 2017

you can also use the whitelist url option

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment