Skip to content

include angular-raven module for plugins #156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

PatrickJS
Copy link

I created an Angular.js module for Raven.js and thought it might be great to include it as a plugin for core

Here is an example using the latest Angular

<body ng-app="YOUR_APP" ng-controller="MainCtrl">
  <a href="#error" ng-click="logError()">Log Error</a>
</body>
<script src="http://cdnjs.cloudflare.com/ajax/libs/raven.js/1.0.8/raven.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.js"></script>
<script>
  Raven.config('YOUR_PUBLIC_DSN', {
      // Raven settings
    })
    .setUser({
      "id": "SERVER_RENDERED_ID",
      "email": "SERVER_RENDERED_EMAIL"
    })
    .install()
<script>
<script src="app/bower_components/angular-raven/angular-raven.js"></script>

<script>
  angular.module('YOUR_APP', [
    'ngRaven',
    'controllers'
  ])
  .config(function(RavenProvider) {
    // There is a development flag to log errors rather than sending it to Sentry
    RavenProvider.development(true);
  });

  angular.module('controllers', [])
    .controller('MainCtrl', function($scope, Raven) {
      $scope.logError = function() {
        Raven.captureMessage('Error');
      };
    });
</script>

@dcramer
Copy link
Member

dcramer commented Nov 11, 2013

+1

Just about to push out the secondary package on an internal project over here. Code looks good on my end from brief skim

@mattrobenolt
Copy link
Contributor

The issues that I have with this are that you're trying to use some functionality which isn't exposed to the global namespace. isFunction() and isUndefined() stand out to me. Also, what's the purpose of essentially copy/pasting Raven.wrap() Not sure what that would be doing in your case.

@PatrickJS
Copy link
Author

I updated the PR to use angular.isFunction() and angular.isUndefined()

I copied to code in order to use captureMessage that checks for the development flag.

    captureMessage: function captureMessage(message, data) {
       if (_development) {
         $log.error('Raven: Message ', message, data);
       } else {
         $window.Raven.captureMessage(message, data);
       }
     },

@dcramer
Copy link
Member

dcramer commented Nov 11, 2013

Of note, I wonder if the development flag would make sense in Raven proper? That would greatly simplify this, and maybe we could just imply development if SENTRY_DSN isnt set?

@PatrickJS
Copy link
Author

if Raven accounted for a development mode (logging errors rather than sending them to Sentry) we can simplify it like so

module.factory( 'Raven', [ '$window', function($window) {
  return $window.Raven
}]);
module.factory('$exceptionHandler', ['Raven', function(Raven) {
  return function(exception, cause) {
    Raven.captureException(exception, cause);
  };
}]);

@PatrickJS
Copy link
Author

I can also allow the user to asynchronously load Raven.js during Angular's configuration phase if they're too lazy to include Raven before Angular. I originally removed that feature because I wanted to make sure Raven to captures all errors before Angular bootstraps including when Angular fails

@mattrobenolt
Copy link
Contributor

Development makes sense. Is there not a way to just conditionally load the Raven module to begin with? I can push for a development mode if it'd be worth it for 1.1.1 or something.

@PatrickJS
Copy link
Author

I can check if Raven is in the global space then load Raven if it's not. Similar to how I handle d3
https://github.com/gdi2290/angular-d3/blob/master/angular-d3.js
I can allow the user to configure Raven just as they normally would with any other Angular module

app.config(function(RavenProvider) {
  var settings = {};
  RavenProvider.config('DSN', settings) //etc
}

Like I said the only problem is that Raven isn't loaded until angular bootstraps (after DOM is ready) I can also load raven.js it outside of Angular and check there.

@mattrobenolt
Copy link
Contributor

@gdi2290 How about we get a working version in, then we can iterate from there? I think for now, if we can clean up the lint warnings so Travis doesn't complain, I'll merge. Then we can add documentation.

@PatrickJS
Copy link
Author

I updated the pull request 4 hours ago it was missing a semicolon. Travis didn't run again I'm not too sure why

@emosenkis
Copy link

What's the status of this? I see there's an angular.js in the plugins folder, but it's not available in the CDN and it doesn't look much like the above code.

@mattrobenolt
Copy link
Contributor

@emosenkis I've rolled my own version, but it hasn't been tested very well, which is why it's not published to the CDN. I was planning on pushing the new ones to CDN as "experimental" status on next release to get feedback.

@PatrickJS PatrickJS deleted the angular-raven branch April 22, 2014 05:41
kamilogorek pushed a commit that referenced this pull request Jun 12, 2018
Coerce error.name to string before assigning as type (fixes #155)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants