4

我似乎无法弄清楚这一点。有人可以帮我解决这个问题吗?我正在使用 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来获取我的源地图?

4

4 回答 4

4

经过一些试验和失败(因为 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
于 2021-06-29T10:56:04.097 回答
0

当您通过 CLI 上传源地图时,您需要Sentry.init使用release和选项调用并传递与标志相同的值。dist

根据哨兵文档

如果您想将 Sentry 与 CodePush 一起使用,您必须将 release 和 dist 传递给 Sentry.init。我们的建议是将它们存储在 app.json 中,或者您可以只使用 package.json。这些值对于您的代码库的每个版本都必须是唯一的,并且与源映射上的版本完全匹配,否则它们可能不会被符号化。

例如:

Sentry.init({
  dsn: YOUR_DSN,
  release: '1.0',
  dist: 'v1',
});

然后当你想上传你的源地图时:

export SENTRY_PROPERTIES=./ios/sentry.properties
sentry-cli react-native appcenter \
account/project \
ios ./build/codePush \
--release-name "1.0" \
--dist "v1"

您的releaseanddist可以是任意字符串,但 Sentry 建议使用以下格式:

${BUNDLE_ID}@${APP_VERSION}+codepush:${DIST}

于 2020-10-28T20:49:14.510 回答
0

我正在处理相同的堆栈,并且捆绑正在哨兵中上传,但我有两个问题:

  1. 在哨兵文件中,他们提供了这个命令-
    sentry-cli react-native appcenter YourApp ios ./build/CodePush --dist YourBuildNumber
    这是什么YourBuildNumber,是应用程序版本,一些哨兵版本号,codepush 版本标签还是其他什么?

  2. 我将错误跟踪作为缩小的 js,有没有办法以文件方式正确获取堆栈跟踪。 错误跟踪哨兵

于 2020-06-02T11:20:54.533 回答
-1

我遇到了同样的问题 - 所有内容都上传到 Sentry 并附加到 Release 中,但 Issues 显示此警告。

对我来说,问题是应用程序和 Sentry Release 中的捆绑 ID 不同,同步这解决了这个问题。

于 2019-07-01T19:06:54.087 回答