提问人:Jordan 提问时间:12/4/2018 更新时间:6/29/2021 访问量:1832
带有 CodePush 的 Sentry React-Native 不使用源映射
Sentry React-Native with CodePush not using source maps
问:
我似乎想不通这一点。有人可以帮我解决这个问题吗?我正在使用 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 来获取我的源映射?
答:
我遇到了同样的问题 - 所有内容都上传到 Sentry 并附加到版本中,但问题显示此警告。
对我来说,问题是应用程序和 Sentry Release 中的捆绑 ID 不同,同步它解决了这个问题。
评论
当您通过 CLI 上传源映射时,您需要调用 and options 并传递与标志相同的值。Sentry.init
release
dist
根据 Sentry Docs
如果要将 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"
Your 和 可以是任意字符串,但 Sentry 建议采用以下格式:release
dist
${BUNDLE_ID}@${APP_VERSION}+codepush:${DIST}
经过一些试验和失败(因为 Sentry 文档具有误导性),终于让 sourcemap 在 iOS 和 Android 上都适用于 AppCenter codepush,在 bash 脚本中执行以下步骤:
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
评论