【问题标题】:Sentry Error logging not working as expected in React Native appSentry 错误日志记录在 React Native 应用程序中未按预期工作
【发布时间】:2021-01-27 07:27:00
【问题描述】:

也许我误解了目的。我正在寻找一种解决方案来替换我的应用程序中的 console.log(errors),因为我已经准备好投入生产。我完成了将 Sentry 功能添加到我的 expo 托管工作流程项目的步骤。它似乎工作,它连接,它运行 Sentry.init() 就好了。但是当我尝试使用 Sentry.captureException('some exception') 代替 console.log 时,应用程序崩溃并且我得到“Sentry.captureException 不是函数”。它在我的哨兵控制台中记录了那个错误。所以错误被传递给我的哨兵项目。但是从我关注的文档来看, 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"
          }
        }
      ]
    }

【问题讨论】:

    标签: expo sentry


    【解决方案1】:

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

    还要注意sentry-expo 支持 TypeScript,因此如果您在项目中使用 TypeScript,您会在调用错误方法时获得自动补全和错误。

    【讨论】:

    • 天哪,我怎么错过了。现在可以了。我一直在这几个小时我的眼睛交叉。谢谢谢谢。我终于可以睡觉了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-02-11
    • 1970-01-01
    • 2018-05-05
    • 1970-01-01
    • 2019-09-27
    • 1970-01-01
    • 2021-05-04
    相关资源
    最近更新 更多