Search code examples
reactjssentryraven

Passing User Information To Sentry through Raven


I have Sentry error tracking set up on a react-application. I use react router 4 and I configure Raven at that level, this catches all exceptions that are thrown and repots them to Sentry which is what I want. That code blocks looks like this:

Raven.config('RAVEN_SPECIFIC_KEY', {
  user: Raven._globalContext
}).install()

However, I'd also like the error report to include the email and database ID of the user that threw the error. To accomplish this I'm setting Raven user information when a person logs in with a code block like so:

Raven.setUserContext({
  id: getState().currentUser.id,
  email: getState().currentUser.email
});

As you can see, right now I have a user tag that I'm setting as Raven._globalContext - this SOMETIMES passes the appropriate information on. I know that accessing the data through the Raven object property like that can't be right, but I'm not sure how to set the Raven options to always pass on the user information that is collected at login. I feel like I'm missing something obvious, but the docks all seem related to passing in information while throwing particular exceptions, where I'd like to configure this so that the user information is passed on whenever any error is thrown.


Solution

  • You don't have to specify a user in your main config if you use setUserContext. That's what is was made for, letting you set which user is currently logged in after you have already initialized Raven. So, just by calling setUserContext, it should backfill all error reports with that users information. You should be able to remove the user property from your config object.