Skip to content

Commit

Permalink
Upgrade to new version of Rollbar for node, and add front-end version…
Browse files Browse the repository at this point in the history
… of Rollbar for client-side errors.
  • Loading branch information
brianlukoff committed Jun 10, 2015
1 parent f7e8825 commit 1f1fb07
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.npm
21 changes: 21 additions & 0 deletions lib/client/rollbar-client.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
Meteor.startup(function() {
Tracker.autorun(function() {
if (Meteor.userId() && Meteor.user()) {
Rollbar.configure({
payload: {
person: {
id: Meteor.userId(),
username: Meteor.user().profile.name
}
}
});
} else {
Rollbar.configure({
payload: {
person: null
}
});
}
});
});

throwError = function() {
Meteor.apply('throwError', arguments, function(err, result) {
if (err) {
Expand Down
10 changes: 10 additions & 0 deletions lib/private/client-head.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<script>
var _rollbarConfig = {
accessToken: "POST_CLIENT_ITEM_ACCESS_TOKEN",
captureUncaught: true,
payload: {
environment: "ENVIRONMENT"
}
};
!function(a,b){function c(b){this.shimId=++h,this.notifier=null,this.parentShim=b,this.logger=function(){},a.console&&void 0===a.console.shimId&&(this.logger=a.console.log)}function d(b,c,d){a._rollbarWrappedError&&(d[4]||(d[4]=a._rollbarWrappedError),d[5]||(d[5]=a._rollbarWrappedError._rollbarContext),a._rollbarWrappedError=null),b.uncaughtError.apply(b,d),c&&c.apply(a,d)}function e(b){var d=c;return g(function(){if(this.notifier)return this.notifier[b].apply(this.notifier,arguments);var c=this,e="scope"===b;e&&(c=new d(this));var f=Array.prototype.slice.call(arguments,0),g={shim:c,method:b,args:f,ts:new Date};return a._rollbarShimQueue.push(g),e?c:void 0})}function f(a,b){if(b.hasOwnProperty&&b.hasOwnProperty("addEventListener")){var c=b.addEventListener;b.addEventListener=function(b,d,e){c.call(this,b,a.wrap(d),e)};var d=b.removeEventListener;b.removeEventListener=function(a,b,c){d.call(this,a,b&&b._wrapped?b._wrapped:b,c)}}}function g(a,b){return b=b||this.logger,function(){try{return a.apply(this,arguments)}catch(c){b("Rollbar internal error:",c)}}}var h=0;c.init=function(a,b){var e=b.globalAlias||"Rollbar";if("object"==typeof a[e])return a[e];a._rollbarShimQueue=[],a._rollbarWrappedError=null,b=b||{};var h=new c;return g(function(){if(h.configure(b),b.captureUncaught){var c=a.onerror;a.onerror=function(){var a=Array.prototype.slice.call(arguments,0);d(h,c,a)};var g,i,j="EventTarget,Window,Node,ApplicationCache,AudioTrackList,ChannelMergerNode,CryptoOperation,EventSource,FileReader,HTMLUnknownElement,IDBDatabase,IDBRequest,IDBTransaction,KeyOperation,MediaController,MessagePort,ModalWindow,Notification,SVGElementInstance,Screen,TextTrack,TextTrackCue,TextTrackList,WebSocket,WebSocketWorker,Worker,XMLHttpRequest,XMLHttpRequestEventTarget,XMLHttpRequestUpload".split(",");for(g=0;g<j.length;++g)i=j[g],a[i]&&a[i].prototype&&f(h,a[i].prototype)}return a[e]=h,h},h.logger)()},c.prototype.loadFull=function(a,b,c,d,e){var f=g(function(){var a=b.createElement("script"),e=b.getElementsByTagName("script")[0];a.src=d.rollbarJsUrl,a.async=!c,a.onload=h,e.parentNode.insertBefore(a,e)},this.logger),h=g(function(){var b;if(void 0===a._rollbarPayloadQueue){var c,d,f,g;for(b=new Error("rollbar.js did not load");c=a._rollbarShimQueue.shift();)for(f=c.args,g=0;g<f.length;++g)if(d=f[g],"function"==typeof d){d(b);break}}"function"==typeof e&&e(b)},this.logger);g(function(){c?f():a.addEventListener?a.addEventListener("load",f,!1):a.attachEvent("onload",f)},this.logger)()},c.prototype.wrap=function(b,c){try{var d;if(d="function"==typeof c?c:function(){return c||{}},"function"!=typeof b)return b;if(b._isWrap)return b;if(!b._wrapped){b._wrapped=function(){try{return b.apply(this,arguments)}catch(c){throw c._rollbarContext=d()||{},c._rollbarContext._wrappedSource=b.toString(),a._rollbarWrappedError=c,c}},b._wrapped._isWrap=!0;for(var e in b)b.hasOwnProperty(e)&&(b._wrapped[e]=b[e])}return b._wrapped}catch(f){return b}};for(var i="log,debug,info,warn,warning,error,critical,global,configure,scope,uncaughtError".split(","),j=0;j<i.length;++j)c.prototype[i[j]]=e(i[j]);var k="//d37gvrvc0wt4s1.cloudfront.net/js/v1.2/rollbar.min.js";_rollbarConfig.rollbarJsUrl=_rollbarConfig.rollbarJsUrl||k;var l=c.init(a,_rollbarConfig);l.loadFull(a,b,!1,_rollbarConfig)}(window,document);
</script>
Empty file removed lib/rollbar.js
Empty file.
18 changes: 9 additions & 9 deletions lib/server/rollbar-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ throwErrorIfNotInitialised = function() {
}
};

//
throwError = function(message) {
check(message, String);
throwErrorIfNotInitialised();
Expand Down Expand Up @@ -95,14 +94,15 @@ Meteor.startup(function() {
if (allNecessaryKeysAvailable()) {
rollbarServerAccessToken = process.env["ROLLBAR_SERVER_ACCESS_TOKEN"];
rollbarClientAccessToken = process.env["ROLLBAR_CLIENT_ACCESS_TOKEN"];
rollbarEnvironment = process.env["ROLLBAR_ENVIRONMENT"];
if (rollbarEnvironment) {
rollbar.init(rollbarServerAccessToken, {
environment: rollbarEnvironment
});
} else {
rollbar.init(rollbarServerAccessToken);
}
rollbarEnvironment = process.env["ROLLBAR_ENVIRONMENT"] || 'development';
rollbar.init(rollbarServerAccessToken, {
environment: rollbarEnvironment
});
Inject.rawHead('rollbar', Assets.getText('lib/private/client-head.html').
replace("POST_CLIENT_ITEM_ACCESS_TOKEN", rollbarClientAccessToken).
replace("ENVIRONMENT", rollbarEnvironment)
);
rollbar.handleUncaughtExceptions(rollbarServerAccessToken, { exitOnUncaughtException: true });
Meteor.methods(methods);
} else {
reportAPIConnectionNotPossible();
Expand Down
6 changes: 3 additions & 3 deletions package.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ Package.onUse(function(api) {
api.versionsFrom('METEOR@1.0');

Npm.depends({
'rollbar': '0.5.3'
'rollbar': '0.5.4'
});

api.use('check', 'server');
api.use('meteorhacks:inject-initial', ['client', 'server']);

api.addFiles('lib/server/rollbar-server.js', 'server');

api.addFiles('lib/rollbar.js', ['client', 'server']);
api.addFiles('lib/client/rollbar-client.js', 'client');
api.addFiles('lib/private/client-head.html', 'server', { isAsset: true });

api.export([
'throwError',
Expand Down

0 comments on commit 1f1fb07

Please sign in to comment.