Giter VIP home page Giter VIP logo

ember-cli-sentry's Introduction

ember-cli-sentry

An ember-cli addon adding Sentry support.


⚠️ this repository isn't maintained any longer ⚠️

➡️ See the official Sentry's Ember addon documentation.


Requirements

  • Node.js 6 or higher is required to use this addon
  • Ember CLI 2.13 or higher is required to use this addon

Install

ember install ember-cli-sentry

Usage

TLDR

// config/environment.js

module.exports = function(environment) {
  var ENV = {

    /* config */

    sentry: {
      dsn: 'https://<dummykey>@app.getsentry.com/<dummyproject>'
    }
  }
}

Complete config

// config/environment.js

module.exports = function(environment) {
  var ENV = {

    /* config */

    sentry: {
      /**
       * The only mandatory parameter.
       *
       * @type {String}
       */
      dsn: 'https://<dummykey>@app.getsentry.com/<dummyproject>',

      /**
       * Sets Raven.debug property when running `Raven.config`.
       *
       * @type {Boolean}
       * @default true
       */
      debug: true,

      /**
       * If set to true, it will prevent Raven.js from being initialized.
       * Errors and logs will be logged to the console (default) instead of
       * being reported by Raven.
       *
       * @type {Boolean}
       * @default undefined
       */
      development: false,
      
      /**
       * Pass the environment to Raven.js
       *
       * @type {String}
       * @default undefined
       */
      environment: environment,

      /**
       * If set to true, addon will try to have Ember.onerror
       * and Ember.RSVP.on('error') captured by Raven.
       *
       * @type {Boolean}
       * @default true
       */
      globalErrorCatching: true,

      /**
       * Raven.js option.
       *
       * @type {Array}
       * @default []
       */
      includePaths: [],

      /**
       * Raven.js option.
       *
       * @type {Array}
       * @default []
       */
      whitelistUrls: [],

      /**
       * Options to pass directly to Raven.js. Note: whitelistUrls and
       * includePaths in this will take precedence
       * over the above.
       *
       * @default {}
       */
      ravenOptions: {},
    }
  }
}

Content Security Policy

To allow Ravenjs to work properly, you need to add a couple of thing to the content security policy rules:

'script-src': "'self' 'unsafe-inline' 'unsafe-eval'",
'img-src': "data: app.getsentry.com",
'connect-src': "'self' app.getsentry.com"

Meaningless stack traces?

See this issue.

Example

The dummy application in tests is a working example with a couple of logging here and there, and a default logger.

Licence

MIT

ember-cli-sentry's People

Contributors

achambers avatar buschtoens avatar dashdashzako avatar dependabot-preview[bot] avatar dependabot-support avatar dependabot[bot] avatar dschmidt avatar ef4 avatar ember-tomster avatar floqqi avatar gabz75 avatar ghedamat avatar grantcupps avatar hussfelt avatar jakehow avatar kkumler avatar marcoow avatar mattmcmanus avatar mazondo avatar oquis avatar robindaugherty avatar rwjblue avatar seriousben avatar tchak avatar tim-evans avatar turbo87 avatar xcambar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ember-cli-sentry's Issues

Unit tests for objects that use sentry never work

(This may be specific to Mocha, not sure.)

When this addon is used properly, it injects the raven service into all controllers, models, etc. And properly using raven, these should call get('raven').captureException and similar in order to report on failures or whatever.

However, in Mocha unit tests for these controllers, models, etc., the app's initializers are not run, so the raven property is never set up. This causes all code like this:

export default Ember.Controller.extend({
  validateCredentials(email, password) {
    return new Ember.RSVP.Promise((resolve, reject) => {
      this.get('session').authenticate('authenticator:oauth2', email, password)
      .then(() => {
        resolve();
      }, () => {
        this.set('errorMessage', 'Invalid credentials');
        reject();
      }).catch((error) => {
        this.set('errorMessage', 'Sorry, there was a problem checking credentials.');
        this.get('raven').captureException(e);
        reject();
      });
    });
  },
});

to fail in any unit test because raven is undefined.

I tried adding it to the test helper but the raven initializer still never gets called.

I also tried injecting the raven service directly into the controller with:

export default Ember.Controller.extend({
  raven: Ember.inject.service('raven'),
});

and then adding it to the unit test's setupTest, and this worked, but it also means that I have to bypass ember-cli-sentry in every model, controller, etc.

Any ideas on how to best utilize ember-cli-sentry while also supporting unit tests?

There were N errors encountered while processing this event

I'm on [email protected] and [email protected].
Have been getting the error on Sentry "There were X errors encountered while processing this event" since ever, due to some error on processing only some sourcemap files (which are all available of course):

screen shot 2017-02-09 at 10 29 10

which result in this:

screen shot 2017-02-09 at 11 05 45

As you can see some sourcemaps are correctly parsed, some are not. Specifically the ones under /vendor.

This has been reported here and Sentry guys commented it to be a Sentry server issue.

Run tests using real sentry dsn

What would really be awesome is to be able to run the tests against a working sentry config, which is unfortunately not possible since this part is hosted by Sentry.

I wish I personally had the money to provide a working dsn, but I don't 😄

May be @mattrobenolt could give us some hints about running the tests more efficiently (testing dsn may be).

Automatically enable sourcemaps

ember-cli disables sourcemaps in production mode which makes sentry's stacktraces pretty much unusable. It would be awesome to automatically enable sourcemaps with this addon so that stuff "just works".

If that's not possible or you'd want this to be an opt-in feature, it would be great to log a warning/error on startup that the deveoper needs to manually enable sourcemaps for sentry's stacktraces to be usable.

Ember build with sourcemaps fails

I just updated to v2.1.1 and when I try to make a production build it fails, apparently because of raven-js and sourcemaps:

ember b -prod    
version: 1.13.8
Build failed.
File: assets/vendor.js
Invalid mapping: {"generated":{"line":68421,"column":-22232},"source":"bower_components/ember-data/ember-data.prod.js","original":{"line":1,"column":0},"name":null}

I know it says it failed with ember-data.prod.js, but if I remove raven-js from bower it works (using the 2.0.0 release)

Test loader failures in ember-cli 0.2.1

I'm not sure if this is related to ember-cli-sentry or not, but I'm seeing test loader failures after upgrading to ember-cli 0.2.1.

Died on test #1     at Object.TestLoader.moduleLoadFailure (http://localhost:4200/assets/test-support.js:5295:11)
    at Object.TestLoader.require (http://localhost:4200/assets/test-loader.js:31:14)
    at Object.TestLoader.loadModules (http://localhost:4200/assets/test-loader.js:21:18)
    at Function.TestLoader.load (http://localhost:4200/assets/test-loader.js:40:24)
    at http://localhost:4200/assets/test-support.js:5301:16
    at d (http://cdn.ravenjs.com/1.1.16/jquery,native/raven.min.js:2:12478): undefined is not a function

Should raven.js be loading in a testing environment? I'm not sure I see a reason for loading it.

Remove "serviceName" option and add service to app by default

I would like to propose the deprecation of the serviceName option. To me it seems very confusing and I don't actually see any advantage of making it configurable since it seems very unlikely that someone actually has another unrelated raven service in his app.

If we remove the serviceName propery and rely on it always being raven we can also add the service to the app folder so that everyone has it by default and only those that want to override certain things will need to generate one for themselves.

This is obviously a breaking change, but IMHO it is a useful one.

Explain dummy app in the README

TypeError: Cannot read property 'enableGlobalErrorCatching' of undefined

Getting this error in the latest version (2.0.0-beta.1). Was not able to reproduce in the dummy app, unfortunately. I'm not sure why it's happening.

I've traced it as far as the container.lookup() in raven-setup.js. For some reason it returns undefined instead of instantiating the service:logger service.

I'll keep debugging, but figured I'd post in case it was something obvious to you.

Cannot configure Raven unless already setup

Unless the install method has been called on the Raven object, all call to callRaven are dropped.

It means that we can't set either tag's context, user context, etc..

In my case, the init on the application route is called before install is call on the Raven service thus ignored.

The only methods that needs the Raven service to be setup are captureMessage/captureException really.

Move some configuration options into the service

If we move e.g. the ignoreErrors option into the service we could use strings and regexes directly instead of having to convert them from stringified regexes.

This could be implemented in multiple steps:

  • move most of the code in the raven-setup instance initializer into a setup() method in the service
  • read ignoreErrors from the service instance if set otherwise fallback to the environment config as before
  • deprecate reading ignoreErrors from the environment config
  • add support for ignoreUrls and other config options that support regexes (resolves #62)
  • remove support for reading ignoreErrors from the environment config (breaking change)

Feedback wanted from Fastboot users

Hi, ember-cli-sentry users,

Does some of you have feedback to share about using this add-on with Fastboot? How the two work together? Have you noticed any weird behavior?

Is there a chance to ignore error and reject reason separately?

When a promise is failed, we call reject(reason). However then the two global error catchings are hit both. But I don't want log them twice. So I want to know is there a chance to ignore error and reason separately? Perhaps we need a hook called ignoreReason?

Ember.onerror = (error) => {
  if (this._ignoreError(error)) {
    return;
  }
}
RSVP.on('error', (reason, label) => {
  if (this._ignoreError(reason)) {
    return;
  }
}

`ember-electron` support

It seems like my map isn't being used or something, but I looked at a forced error I generated with debug on and saw culprit: "serve://dist/".

I am using this inside an ember-electron project, however, I feel like it shouldn't effect anything considering it's still running in an ember environment. I tried uploading sourcemaps and built files to my releases in Sentry, but this console output makes me thing that no matter what I change on Sentry's side, nothing will fix it.

My config/environment.js:

sentry: {
  dsn: 'https://[email protected]/xx',
  debug: true,
}

Uncaught promises logged twice to Sentry

We're using this library and it seems to log uncaught promises twice to Sentry. Once, in Ember.onerror and once in RSVP.on('error', ...). When it's logged through Ember.onerror, it also incorrectly calls caputreExcpetion with the reason object, which is not an error -- leading to it just being logged as [object Object].

Has anyone else dealt with or seen this?

Best way to add context to error reports?

First, thanks for this addon. I was beginning to gear up to write my own addon for Sentry integration before finding this and thought I'd give this a try before rolling my own.

I do have a question though, and it surrounds tagging and adding context to errors being reported to Sentry. If I wanted to add a user context to the errors, Sentry's documentation suggests doing something like the following:

Raven.setUserContext({
    email: '[email protected]',
    id: '123'
})

I'm not sure necessarily how to go about this with your addon. Would it be correct to extend ember-cli-sentry/services/raven to add this in? If you could provide some guidance on this matter, I'd really appreciate it.

Thanks!

New release

Thanks for the addon! We recently incorporated it into a project and are trying to upgrade to Ember 2.5, but are getting deprecation warnings. It looks like that was recently fixed. Could you release a new version to incorporate that change?

Capturing exceptions when development mode is true

Thanks for the plugin - really useful!

In the readme, you state the application route should do the following if you want to trap routing errors:

actions: {
  error: function (err) {
    Raven.captureException(err);
  }
}

However, when development mode is true, this results in Raven console logging that Raven has not been configured.

I've tried this:

actions: {
  error: function (err) {
    if (Raven.isSetup()) {
       Raven.captureException(err);
    }
  }
}

but I still get the same message. Any ideas on how to detect whether Raven is usable?

Add vendor shim for `raven`

Whether we import raven-js from bower, npm or CDN we always have to deal with window.Raven. It would be great if we could just include a vendor shim so that we could import Raven from 'raven'; instead of using the global.

Lots of <unlabeled event> events

I'm getting a lot of <unlabeled event> events in Sentry.io.

I enabled sourcemaps as specified in #28, I also have globalErrorCatching set to true.

As far as I understand, sync exceptions bubble up to Application's main route.js, where I have my

    error(error) {
      if (ENV.sentry.development === false) {
        get(this, 'raven').captureException(error);
      }
    }

Also globalErrorCatching should catch async exceptions, right?

Debug info:

DEBUG: -------------------------------
DEBUG: Ember             : 2.7.3
DEBUG: Ember Data        : 2.8.1
DEBUG: jQuery            : 2.2.4
DEBUG: Ember Simple Auth : 1.1.0
DEBUG: Model Fragments   : 2.3.2
DEBUG: -------------------------------

Is there a guide and/or part of the documentation about best practices for error logging in ember apps?

Cheers!

*UPDATE: Inspecting the error object it consist of an Array of errors, usually containing only 1 error. This probably changed in recent versions of ember-data.

How to prevent some types of errors from being reported

I must be doing something wrong :)

    if (isPresent(recordId)) {
      try {
        get(this, 'store').findRecord('customer-device', recordId, { reload: true }).then((customerDevice) => {
           console.log(get(customerDevice, 'status'));
        });
      } catch(err) {
        console.debug(err);
      }
    }

In the use case that findRecord returns a 404, I CANNOT seem to prevent that 404 from being reported to sentry.

I have it in a try catch / not sure what further I need to do.

(in this case it is doing a 404 because the current user doesn't have permission to see the record, and we are doing a 404 vs a 403)

Raven catches everything in console, not sure how to disable?

after installing ember-cli-sentry and configuring the Raven.js. I have noticed that almost all error logs and console logs are called through raven now and it is hard to locate where the message originates from?

For example if i were to put a console.log('hello') into one of my model hooks. when i view the output in developer console, the source of the log comes from raven.js now.. throughth a wrapMethod function.. now i can no longer see where my console log is coming from...

I know that this is a raven issue primarily.. but i cant find any docs here or in sentry/raven that describe how i can disable this? or how I could possible use it to my advantage? I am hoping soeone here has encountered it an knows the answer?

Add FastBoot support

Currently it'll always try to app.import the Raven JS library, even in FastBoot (server side).
This results in the below error for every request:

Error: Raven has already been configured

We should wrap the app.import with a check for process.env.EMBER_CLI_FASTBOOT in index.js:

    try {
      var stats = fs.statSync(app.bowerDirectory + '/raven-js/dist/raven.js');
      if (!stats.errno && !process.env.EMBER_CLI_FASTBOOT) {
        app.import(app.bowerDirectory + '/raven-js/dist/raven.js');
      }
    } catch (e) {
      console.log('ember-cli-sentry will not be loaded from bower installation');
    }

Better first usage experience

First of all, thanks for creating this addon! I never used it before so my experience while setting it up is still fresh. I did following steps to get going:

  1. Install the addon.
  2. Install the raven-js dependency via Bower.
  3. Import the raven-js dependency.
  4. Create the raven service.
  5. Modify the CSP rules.
  6. Setup the config so it does not track in development build.
  7. Setup the config so it tracks in production builds.

Steps 2, 3 and 4 could be done by the addon itself when it's installed. This would simplify the getting started process for beginners significantly.

Are you open for a pull request implementing this?

Latest releases are assuming raven.js is inlined

You can no longer use the cdn option.

Build failed.
ENOENT: no such file or directory, stat '/Users/devinus/Projects/rebelmail-dashboard/tmp/source_map_concat-input_base_path-ZMpdzNJt.tmp/0/bower_components/raven-js/dist/raven.js'
Error: ENOENT: no such file or directory, stat '/Users/devinus/Projects/rebelmail-dashboard/tmp/source_map_concat-input_base_path-ZMpdzNJt.tmp/0/bower_components/raven-js/dist/raven.js'
    at Error (native)
    at Object.fs.statSync (fs.js:892:18)
    at ConcatWithMaps.keyForFile (/Users/devinus/Projects/rebelmail-dashboard/node_modules/broccoli-caching-writer/index.js:90:20)
    at Array.map (native)
    at ConcatWithMaps.CachingWriter._conditionalBuild (/Users/devinus/Projects/rebelmail-dashboard/node_modules/broccoli-caching-writer/index.js:112:65)
    at /Users/devinus/Projects/rebelmail-dashboard/node_modules/broccoli-caching-writer/node_modules/broccoli-plugin/read_compat.js:61:34
    at lib$rsvp$$internal$$tryCatch (/Users/devinus/Projects/rebelmail-dashboard/node_modules/rsvp/dist/rsvp.js:493:16)
    at lib$rsvp$$internal$$invokeCallback (/Users/devinus/Projects/rebelmail-dashboard/node_modules/rsvp/dist/rsvp.js:505:17)
    at lib$rsvp$$internal$$publish (/Users/devinus/Projects/rebelmail-dashboard/node_modules/rsvp/dist/rsvp.js:476:11)
    at lib$rsvp$asap$$flush (/Users/devinus/Projects/rebelmail-dashboard/node_modules/rsvp/dist/rsvp.js:1198:9)
    at nextTickCallbackWith0Args (node.js:456:9)
    at process._tickDomainCallback (node.js:426:13)
npm ERR! Test failed.  See above for more details.

It doesn't seem to log exceptions from fastboot

It doesn't seem to work with fastboot?

2016-10-02T04:24:27.118Z 200 OK /website/our-work
Error: Raven has already been configured
Error while processing route: website.our-work.index Adapter operation failed Error: Adapter operation failed
    at new Error (native)
    at Error.t (/home/deploy/mediapop/staging/src/frontend/dist/fastboot/vendor-3ad452d7e54e7df8917456b27bab3c58.js:8:31720)
    at Error.i (/home/deploy/mediapop/staging/src/frontend/dist/fastboot/vendor-3ad452d7e54e7df8917456b27bab3c58.js:22:26)
    at r.handleResponse (/home/deploy/mediapop/staging/src/frontend/dist/fastboot/vendor-3ad452d7e54e7df8917456b27bab3c58.js:23:2850)
    at l (/home/deploy/mediapop/staging/src/frontend/dist/fastboot/vendor-3ad452d7e54e7df8917456b27bab3c58.js:22:3444)
    at Object.c.error (/home/deploy/mediapop/staging/src/frontend/dist/fastboot/vendor-3ad452d7e54e7df8917456b27bab3c58.js:22:6859)
    at fire (/home/deploy/mediapop/staging/src/frontend/node_modules/jquery-deferred/lib/jquery-callbacks.js:78:30)
    at Object.fireWith (/home/deploy/mediapop/staging/src/frontend/node_modules/jquery-deferred/lib/jquery-callbacks.js:188:7)
    at Object.fire [as reject] (/home/deploy/mediapop/staging/src/frontend/node_modules/jquery-deferred/lib/jquery-callbacks.js:195:10)
    at onError (/home/deploy/mediapop/staging/src/frontend/node_modules/najax/lib/najax.js:206:9)
    at dataHandler (/home/deploy/mediapop/staging/src/frontend/node_modules/najax/lib/najax.js:141:18)
    at IncomingMessage.<anonymous> (/home/deploy/mediapop/staging/src/frontend/node_modules/najax/lib/najax.js:194:9)
    at emitNone (events.js:91:20)
    at IncomingMessage.emit (events.js:185:7)
    at endReadableNT (_stream_readable.js:974:12)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
    at process._tickCallback (internal/process/next_tick.js:98:9)

Uncaught ReferenceError: Raven is not defined

After running ember install:addon ember-cli-sentry and configuring the sentry ENV variables I get:

Uncaught ReferenceError: Raven is not defined

Is there anything else I need to install, if so which packages?

This is using ember version 1.9.1 and ember-cli version 0.1.12.

Log error to console on add-on initialize

Hi @damiencaselli

I tried to setup this addon in my project but I end up with unconfigured Raven instance for some reason.

After a couple hours of investigation I found out that I copied wrong dsn from my Sentry account ( it was correct but contained personal key in it ). And Raven.js does not allow such dsn.
The thing is - this Raven.js error was suppressed by this try/catch block.
https://github.com/damiencaselli/ember-cli-sentry/blob/master/app/instance-initializers/raven-setup.js#L35

Can you add more verbose error output in catch block ?
Something like console.warn(e);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.