哨兵错误日志记录在 React Native 应用程序中未按预期工作

时间:2021-01-27 07:27:00

标签: expo sentry

也许我误解了目的。我正在寻找一种解决方案来替换我的应用程序中的 console.log(errors) ,因为我准备好进行生产了。我完成了将 Sentry 功能添加到我的博览会托管工作流程项目的步骤。它似乎工作,它连接,它运行 Sentry.init() 就好了。但是当我尝试使用 Sentry.captureException('some exception') 代替 console.log 时,应用程序崩溃并且我得到“Sentry.captureException is not a function”。它在我的哨兵控制台中记录了那个错误。所以错误被传递给我的哨兵项目。但是从我关注的文档来看,Sentry.captureException 应该是一个有效的函数?我错过了什么?我也尝试过 Sentry.captureMessage,结果相同。

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 博览会挂钩

"hooks": {
      "postPublish": [
        {
          "file": "sentry-expo/upload-sourcemaps",
          "config": {
            "organization": "myorganization",
            "project": "myproject",
            "authToken": "xxxx"
          }
        }
      ]
    }

1 个答案:

答案 0 :(得分:2)

您应该使用 Sentry.Native.captureException('message') - 按照 these docs

另请注意,sentry-expo 支持 TypeScript,因此如果您将 TypeScript 用于您的项目,您将在调用错误方法时获得自动完成和错误。

相关问题