Logout saga (I am using redux-saga):
export function * logout() {
API.setHeader('X-Token', '');
yield call(AsyncStorage.removeItem, 'currentUser');
Sentry.clearContext();
alert('test clear');
}
The alert('test clear') never gets executed, remove the Sentry.clearContext(); then it pops up an alert.
OS: iOS & Android
RN version: 0.44
react-native-sentry version: 0.8.1
The setUserContext method on raven-js supports call setUserContext() with no argument to clear user context, but react-native-sentry seems not supporting that so I have to call clearContext().
static clearContext(clearContext) {
if (Sentry.isNativeClientAvailable()) Sentry._nativeClient.clearContext();
// Sentry._ravenClient.clearContext();
}
The problem seems not related to nativeClient but ravenClient, comment out Sentry._ravenClient.clearContext(); works fine.
BTW, the setUserContext of raven-js documentation seems advice us to pass user id as id while react-native-sentry requires userID.
https://docs.sentry.io/clients/javascript/usage/#tracking-users
I was planning to use clearContext() from within a logout saga just like you, so this will also be an issue for me. Hopefully it's fixed soon.
@HazAT, just confirming that Sentry.clearContext() appears to be working fine for me in 0.14.0, thanks for the fix.
Yeah but how do we clear the user context without other context infos?
With Raven it was Raven.setUserContext() but with Sentry it crashes because it takes an object:
java.lang.NullPointerException: Attempt to invoke interface method 'boolean com.facebook.react.bridge.ReadableMap.hasKey(java.lang.String)' on a null object reference
at io.sentry.RNSentryModule.getUserBuilder(RNSentryModule.java:263)
at io.sentry.RNSentryModule.setUser(RNSentryModule.java:158)
Should we call Sentry.setUserContext({})?
@antoinerousseau If it works like that, yes use Sentry.setUserContext({})
Most helpful comment
@antoinerousseau If it works like that, yes use
Sentry.setUserContext({})