Calling Sentry.setUserContext() from Another Component

In my App.js I have the typical setup…

// App.js

import Sentry from 'sentry-expo';
Sentry.enableInExpoDevelopment = true; // TODO: remove once setup correctly
Sentry.config(SENTRY_PUBLIC_DSN).install();

Later, in my RootNavigation I have login logic and want to setUserContext so I do this…

// RootNavigation.js

import Sentry from 'sentry-expo';
...
createSession = ({ data }) => {
    const { jwt, fullName, email, id } = data.login;
    setSessionToken(jwt);
    Sentry.setUserContext({ userId: id, email, fullName });
    this.setState({ authenticated: true, submitting: false });
  };

My question is, is this the right way to go about this? The docs don’t specify, but I’m assuming that the Sentry object is a singleton. Not sure how to verify it, and the user data isn’t getting passed along with the errors as I’d expect if my assumption were true.

UPDATE: nevermind…this seems to be working now. Not sure if it has something to do with the upgrade to SDK v27.0.0 or the fact that I’ve uninstalled/reinstalled Expo, but all seems to be working as expected now.

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.