react-native - Sentry React-Native with CodePush 不使用源映射

标签 react-native sentry code-push

我似乎无法弄清楚这一点。有人可以帮我解决这个问题吗?我正在使用 CodePush 上传我的应用程序,我希望 Sentry 处理我的错误,因为 appcenter 诊断不是很好。

我在我的应用程序的根组件中有这个...

if (process.env.NODE_ENV === 'production') {
  Sentry.config('****',{
    deactivateStacktraceMerging: false
  }).install();
  codePush.getUpdateMetadata().then((update) => {
    if (update) {
      Sentry.setVersion(update.appVersion + '-codepush:' + update.label);
    }
  });
}

我有一个部署包脚本,它将部署到 codepush 并运行在他们的文档中找到的哨兵命令
appcenter codepush release-react -a account/project --output-dir ./build && export SENTRY_PROPERTIES=./ios/sentry.properties && sentry-cli react-native appcenter account/project ios ./build/codePush
每次我捕获到错误或我捕获到的错误时,我都缺乏有关引发错误的文件的实际信息,我看到 There was 1 error encountered while processing this event在顶部写着 Source code was not found for app:///main.jsbundle当我展开它。

我觉得这一定是哨兵没有正确连接到 codepush 来获取我的源 map 的问题?

最佳答案

经过一些试验和失败(因为 Sentry 文档具有误导性),按照 bash 脚本中的以下步骤,最终使源映射适用于 iOS 和 Android,并使用 AppCenter 代码推送:

MY_APP_NAME="e.g. Sentry account/project"
MY_BUNDLE_ID="e.g. com.company.superapp"
MY_APP_ENV="e.g. development, staging or production"
NATIVE_VERSION="e.g. 1.2.3"
PLATFORM="e.g. ios or android"

# Build and release to appcenter
appcenter codepush release-react \
-a "$MY_APP_NAME" \
-d "$MY_APP_ENV" \
-m -t "$NATIVE_VERSION" \
--sourcemap-output \
--output-dir "./build/$PLATFORM"

export SENTRY_PROPERTIES="./$PLATFORM/sentry.properties"

# Get label and name of latest release
LABEL=$(appcenter codepush deployment history $MY_APP_ENV -a $MY_APP_NAME --output json | jq '.[-1][0]' -r)
RELEASE_NAME="$MY_BUNDLE_ID@$NATIVE_VERSION+codepush:$LABEL"


# Upload sourcemap
sentry-cli react-native appcenter \
"$MY_APP_NAME" "$PLATFORM" "./build/$PLATFORM/CodePush" \
--deployment "$MY_APP_ENV" \
--release-name "$RELEASE_NAME" \
--dist "$LABEL"

并在 app.ts(或类似的)中进行初始化:
  Sentry.init({...});

  codePush.getUpdateMetadata().then(update => {
    if (update) {
      if (MY_APP_ENV === 'production')) {
        Sentry.setRelease(
          `${MY_BUNDLE_ID}@${update.appVersion}+codepush:${update.label}`,
        );
      } else {
        Sentry.setRelease(
          `${MY_BUNDLE_ID}.${MY_APP_ENV}@${update.appVersion}+codepush:${update.label}`,
        );
      }
      Sentry.setDist(update.label);
    }
  });

环境:
appcenter version: 2.7.3
@sentry/react-native: 2.5.1

关于react-native - Sentry React-Native with CodePush 不使用源映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53616302/

相关文章:

python - 乌鸦不向 Sentry 报告异常

javascript - 构建 Microsoft CodePush 时接收内存不足的 javascript 堆

ios - 代码推送 : How to deploy to multiple build versions of the same deployment config?

javascript - 模拟函数是 `undefined` 但单元测试不会失败

react-native - react native 错误 : Unable to resolve module `./index` in node_modules/react-native

javascript - 移动设备隐式流上的静默刷新 token

reactjs - Sentry - React - 捕获错误 iframe 和仅 iframe

spring-boot - 如何将属性从 application.properties 传递到 logback 配置文件

swift - 将 MicroSoft CodePush 集成到 Swift 项目

react-native - 如何使用 expo 管理的工作流程创建离线 apk(不使用 expo 发布或在某处托管 Assets )?