Created
September 19, 2014 17:46
-
-
Save bradvogel/2cf3b92cbf10f4718801 to your computer and use it in GitHub Desktop.
Meteor JS and Sentry / Raven logging integration
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
// 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); | |
}; |
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
// 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