Created
December 19, 2016 15:14
-
-
Save TimFletcher/57e2b9b81501a9e5326cf4899ff010f5 to your computer and use it in GitHub Desktop.
meteor sentry package
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* global Raven, Meteor */ | |
/* eslint-disable no-console */ | |
// If you don't configure the Sentry client (i.e. don't set a DSN) it won't send data. | |
if (Meteor.isClient && Meteor.settings.public.sentry.dsn) { | |
console.log('Initializing Sentry...'); | |
Raven.config( | |
Meteor.settings.public.sentry.dsn, { | |
serverName: Meteor.settings.public.hostUrl, | |
// whitelistUrls: [/touchmail\.io/, /staging\.touchmail\.io/], | |
environment: Meteor.settings.public.mode, | |
}; | |
).install(); | |
Raven.setTagsContext({ | |
server_name: Meteor.settings.public.hostUrl, | |
environment: Meteor.settings.public.mode, | |
}); | |
Meteor.autorun(function() { | |
var user = Meteor.user(); | |
if (user) { | |
Raven.setUserContext({ | |
id: user._id, | |
name: user.profile.firstName + ' ' + user.profile.lastName, | |
email: user.emails[0].address, | |
connectedNylas: !! user.profile.nylas, | |
}); | |
} else { | |
Raven.setUserContext(/* Unset user when they log out */); | |
} | |
}); | |
} | |
RavenLogger = Raven; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* globals Package, Npm */ | |
Package.describe({ | |
name: 'touchmail:sentry', | |
version: '0.0.1', | |
summary: 'Client and server error logging', | |
}); | |
Npm.depends({ raven: '0.11.0' }); | |
Package.onUse(function(api) { | |
api.versionsFrom('[email protected]'); | |
api.addFiles('server.js', 'server'); | |
api.addFiles(['./vendor/raven.js', 'client.js'], 'client'); | |
api.export('RavenLogger', ['client', 'server']); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is all in ES5 because Meteor's ES6 shit breaks here. | |
/* global Raven, Meteor, Npm */ | |
/* eslint-disable no-console */ | |
/** | |
* The only thing you can do on the server to report errors is: | |
* | |
* try { | |
* doSomething(a[0]) | |
* } catch (err) { | |
* client.captureException(err) | |
* } | |
* | |
* On the client you have other options like .context() | |
* | |
*/ | |
var raven = Npm.require('raven'); | |
var client; | |
if (Meteor.settings.sentry.dsn) { | |
console.log('Initializing Sentry with DSN...'); | |
client = new raven.Client(Meteor.settings.sentry.dsn); | |
client.setTagsContext({ | |
server_name: Meteor.settings.public.hostUrl, | |
environment: Meteor.settings.public.mode, | |
}); | |
client.on('logged', function(){ | |
console.log('Error successfully logged to Sentry'); | |
}); | |
client.on('error', function(error) { | |
// The event contains information about the failure: | |
// e.reason -- raw response body | |
// e.statusCode -- response status code | |
// e.response -- raw http response object | |
console.log('Error failed to be logged to Sentry: ' + error.toJSON()); | |
}); | |
client.patchGlobal(function() { | |
console.log('A fatal error'); | |
process.exit(1); | |
}); | |
} else { | |
console.log('Initializing Sentry without DSN (will not send data to Sentry)'); | |
// Passing any falsey value as the DSN will disable sending events upstream: | |
client = new raven.Client(false); | |
} | |
RavenLogger = client; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment