getsentry / raven-node

A standalone (Node.js) client for Sentry
https://sentry.io/
BSD 2-Clause "Simplified" License
454 stars 135 forks source link

Ability to see errors in console #259

Open qrpike opened 7 years ago

qrpike commented 7 years ago

I have Raven setup buy my biggest issue is when I'm developing locally I still want to see the messages in my console.

Adding:

Raven.on('logged', function(e){
    console.log('Raven Logged:', e)
})

Only shows me the event ID. How can I also console log the error. Maybe like:

Raven.on('logged', function(e, err){
    console.log('Raven Logged:', e, err)
})

Thanks,

LewisJEllis commented 7 years ago

There's not a particularly good way to do this right now, but #180 is an older PR for roughly the change you're suggesting. The events emitted by Raven are going to need some tweaking with the changes coming for #257, so I'll make sure to keep this in mind.

esetnik commented 7 years ago

@qrpike I'm not sure whether you're referring to uncaughtExceptions but you can use something like:

const ravenEnabled = config.get('sentry.enabled');
const ravenClient = Raven.config(ravenEnabled ? ravenDsn : null).install(function(logged, err) {
  log.error('process is terminating due to uncaught exception', err);
  process.exit(1);
});

However this function only gets called when a ravenDsn is supplied. I have opened https://github.com/getsentry/raven-node/pull/283 to address that particular deficiency with this solution.

oliviertassinari commented 7 years ago

My best workaround so far is to monkey patch raven method:


function override(object, methodName, callback) {
  // eslint-disable-next-line no-param-reassign
  object[methodName] = callback(object[methodName])
}

// Monkey patch 🐒
override(raven, 'captureException', original => {
  return (...args) => {
    // Useful for debugging
    if (process.env.NODE_ENV !== 'test') {
      // eslint-disable-next-line no-console
      console.warn('raven.captureException', ...args)
    }

    original.apply(raven, args)
  }
})