Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
780 views
in Technique[技术] by (71.8m points)

expo - Sentry Error logging not working as expected in React Native app

Maybe I'm misunderstanding the purpose. I am looking for a solution to replace my console.log(errors) in my app as I get it ready for production. I went through the steps to add Sentry functionality to my expo managed work flow project. It seemed to work, it connects, it runs Sentry.init() just fine. But when I try to use Sentry.captureException('some exception') in place of a console.log, the app crashes and I get "Sentry.captureException is not a function". It logs THAT error in my sentry console. So the error is being passed to my sentry project. But from the documentation I'm following, Sentry.captureException should be a valid function? What am i missing? I have also tried Sentry.captureMessage with the same result.

App.js

import * as Sentry from 'sentry-expo';

Sentry.init({
  dsn: 'xxxx',
  enableInExpoDevelopment: true,
  debug: true, // Sentry will try to print out useful debugging information if something goes wrong with sending an event. Set this to `false` in production.
});

enableScreens();

export default function App() {
  return (
    <NavigationContainer>
      <AuthNavigator />
    </NavigationContainer>
  )
}

app.json expo hooks

"hooks": {
      "postPublish": [
        {
          "file": "sentry-expo/upload-sourcemaps",
          "config": {
            "organization": "myorganization",
            "project": "myproject",
            "authToken": "xxxx"
          }
        }
      ]
    }
question from:https://stackoverflow.com/questions/65914595/sentry-error-logging-not-working-as-expected-in-react-native-app

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You should use Sentry.Native.captureException('message') - as per these docs.

Also note that sentry-expo supports TypeScript, so if you were to use TypeScript for your project you would get autocompletion and an error when calling the wrong method.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...