adopted-ember-addons / ember-cli-bugsnag

Integrates Bugsnag reporting service into your Ember CLI app.
MIT License
20 stars 33 forks source link

user/metadata not always provided when using Bugsnag.notifyException #84

Open machty opened 6 years ago

machty commented 6 years ago

I'm reviewing some recent Bugsnags and realizing that the user and metadata tags are not always provided as part of the Bugsnag. I'm not 100% certain but I believe it's because there's some instances in our app where we recover from an error but still want to use Bugsnag.notifyException.

The problem seems to be, from my understanding of that code, that getUser() and getMetadata() don't get called except from within onerror: https://github.com/binhums/ember-cli-bugsnag/blob/master/app/instance-initializers/bugsnag.js#L50

The result of this seems to be that if the first Bugsnag report issued is a manual notifyException, it won't contain pull in your user data / metadata. But if an onerror occurred, it'll set these values for all future notifyExceptions.

I'm surprised no one's noticed this; it makes me wonder if I'm misusing the API somehow? Is it ok that I'm still using Bugsnag.notifyException to report handled exceptions? Or is there a better workflow?

flexyford commented 5 years ago

@machty We encountered the same issue where user data was not provided in Bugsnag. My solution was to report handled exceptions by explicitly calling Ember.onerror. I'm not thrilled with this approach, so if anyone alternative solutions they would be much appreciated :)

// app/utils/bugsnag-exception.js
import Ember from 'ember';

/* Handled Exceptions can be reported as follows:
   try {
     // Some code which might throw an exception
   } catch (error) {
     bugsnagNotifyException(error, name);
   }
*/
export default function bugsnagNotifyException(e, name) {
  if (Ember.onerror) { 
    e.name = name || e.name;
    Ember.onerror(e);
  }
}