CodePush
为 CodePush 发布版本上传源映射。
Sentry 的 React Native SDK 开箱即用支持 CodePush。要在产品中看到可读的堆栈跟踪,你必须将源映射上传到 Sentry。本指南解释了如何为使用 AppCenter CLI 创建的 CodePush 发布版本上传源映射。
- 注册一个账户
- 设置 Sentry React Native SDK
- 设置 Sentry Metro 插件
- 该插件确保启用了 Debug ID,并用于将源映射链接到捆绑包。
确保 codePush
是最外层的函数,因为它需要访问根组件以替换捆绑包。
export default codePush(Sentry.wrap(App));
为了确保 Sentry 能够符号化来自你的 CodePush 发布版本的事件,你需要生成并上传必要的资源。在创建 CodePush 发布版本时,包含 --sourcemap-output-dir
标志以生成源映射。这将允许你在下一步中将这些文件上传到 Sentry。
appcenter codepush release-react \
--app "${APP_NAME}" \
--deployment-name "${DEPLOYMENT_NAME}" \
--output-dir ./build \
--sourcemap-output-dir ./build
如果你使用的是 Hermes,请确保你的系统上已安装 jq
。如果没有安装,可以使用系统的包管理器进行安装。例如,在 Ubuntu 上使用 apt-get install jq
,或在 macOS 上使用 Homebrew 运行 brew install jq
。
通过设置环境变量并运行 sourcemaps upload
命令来为你的 CodePush 发布版本上传源映射。
在运行上传命令之前,请确保设置好环境变量。
export SENTRY_ORG=example-org
export SENTRY_PROJECT=example-project
export SENTRY_AUTH_TOKEN=sntrys_YOUR_TOKEN_HERE
要为你的 CodePush 发布版本上传源映射,请使用 sourcemaps upload
命令。
npx sentry-cli sourcemaps upload \
--debug-id-reference \
--strip-prefix /path/to/project/root \
./build
为了将上传的工件与 CodePush 发布版本关联,请使用 --release
和 --dist
选项,这些是 sentry-cli 命令的参数。确保 SDK 报告的事件具有相同的 release
和 dist
值。你可以使用默认模式 ${BUNDLE}@${VERSION}+${BUILD}
作为 release
,${BUILD}
作为 dist
,或在 Sentry.init
中手动设置这些值。当使用带有 Debug ID 的工件时,这是可选的。
如果你依赖 codePush.getUpdateMetadata
来获取 CodePush 更新标签,请使用 Sentry.setTag
将 CodePush 更新标签与捕获的事件关联。这将使你能够在 Sentry UI 中根据标签过滤事件。我们不建议使用 codePush.getUpdateMetadata
来初始化 SDK,因为这会延迟初始化,并且在 CodePush 更新标签可用之前发生的错误不会报告给 Sentry。
codePush.getUpdateMetadata().then((update) => {
Sentry.setTag("codepush", update.label);
});