Skip to content

Instantly share code, notes, and snippets.

@bradvogel
Created September 19, 2014 17:46
Show Gist options
  • Save bradvogel/2cf3b92cbf10f4718801 to your computer and use it in GitHub Desktop.
Save bradvogel/2cf3b92cbf10f4718801 to your computer and use it in GitHub Desktop.
Meteor JS and Sentry / Raven logging integration
// Setting up Raven and Meteor on the CLIENT side.
var clientDSN = 'https://<key>@app.getsentry.com/30405';
Raven.config(clientDSN, {}).install();
// Set the user automatically.
Meteor.autorun(function() {
var user = Meteor.user();
if (!user) Raven.setUser( /* Unset */ );
else {
Raven.setUser({
id: user._id,
name: user.profile.name,
email: user.services.google.email
});
}
});
// Optionally abstract the Raven.captureMessage() to be symmetrical with the server (see below).
error = function(message) {
Raven.captureMessage(message);
};
// Setting up Raven and Meteor on the SERVER side.
var serverDSN = Environment.is(Environment.LOCAL) ? false /* Disable */ : 'https://<key>:<secret>@app.getsentry.com/30405';
var Raven = new(Meteor.npmRequire('raven')).Client(serverDSN);
// Returns the user context ONLY IF we're inside a Meteor method context.
function getUserContext() {
try {
var user = Meteor.user();
if (user) {
return {
id: user._id,
email: user.services.google.email,
name: user.profile.name
}
}
} catch (e) { /* Ignore exception from Meteor.user() */ }
}
/**
* Abstract raven logging function so we can add in the user context.
*/
error = function(message) {
// Don't send analytics from local.
Raven.captureMessage(message, {
// See https://github.com/getsentry/raven-node/issues/54.
'sentry.interfaces.User': getUserContext()
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment