Expo(高级)
手动为原生 Expo 发布版本上传源映射。
Sentry 的 React Native SDK 开箱即用支持 Expo 应用程序。要在产品中看到可读的堆栈跟踪,你必须将源映射上传到 Sentry。本指南解释了如何手动为 Expo 应用程序发布版本上传源映射。
有关如何自动为 Expo 应用程序发布或更新版本上传源映射的指南,请参阅 Expo 源映射文档。
- 注册一个账户
- 从
sentry-expo
迁移到@sentry/react-native
- 设置 Sentry React Native SDK 版本 5.16.0-alpha.4 或更新版本
要上传 source maps,需要将 Sentry Expo 插件和 Sentry Metro 插件添加到 Expo 应用程序中。
为了确保在本地和 EAS 原生应用程序构建期间自动上传 bundles 和 source maps,请将 @sentry/react-native/expo
配置插件添加到 Expo 应用程序配置中:
{
"expo": {
"plugins": [
[
"@sentry/react-native/expo",
{
"url": "https://sentry.io/",
"note": "Use SENTRY_AUTH_TOKEN env to authenticate with Sentry.",
"project": "example-project",
"organization": "example-org"
}
]
]
}
}
将身份验证令牌添加到你的环境:
# DO NOT COMMIT YOUR AUTH TOKEN
export SENTRY_AUTH_TOKEN=sntrys_YOUR_TOKEN_HERE
为了确保生成的 bundles 和 source maps 被分配唯一的 Debug ID,请将 Sentry Metro 插件添加到配置中:
// const { getDefaultConfig } = require("expo/metro-config");
const { getSentryExpoConfig } = require("@sentry/react-native/metro");
// const config = getDefaultConfig(__dirname);
const config = getSentryExpoConfig(__dirname);
module.exports = config;
在将 Sentry Expo 插件和 Sentry Metro 插件添加到应用程序配置后,生成并上传 Hermes 源映射。
要为原生应用程序发布版本生成捆绑包和源映射,请使用以下命令:
# --entry-file node_modules/expo-router/entry.js \
npx expo export:embed \
--entry-file node_modules/expo/AppEntry.js \
--platform android \
--dev false \
--reset-cache \
--bundle-output index.android.bundle \
--sourcemap-output index.android.bundle.packager.map \
--minify false
- 实际命令可能根据你的应用程序配置有所不同。上述命令是 Expo 默认使用的命令。
- 捆绑包和源映射的名称可能会改变生成的调试 ID。
- 对于自定义入口文件路径,需要调整
--entry-file
参数。
编译 Hermes 字节码捆绑包和源映射:
node_modules/react-native/sdks/hermesc/osx-bin/hermesc \
-O -emit-binary \
-output-source-map \
-out=index.android.bundle.hbc \
index.android.bundle
rm -f index.android.bundle
mv index.android.bundle.hbc index.android.bundle
组成 Hermes 字节码和(React Native Packager)Metro 源映射:
node \
node_modules/react-native/scripts/compose-source-maps.js \
index.android.bundle.packager.map \
index.android.bundle.hbc.map \
-o index.android.bundle.map
node \
node_modules/@sentry/react-native/scripts/copy-debugid.js \
index.android.bundle.packager.map index.android.bundle.map
rm -f index.android.bundle.packager.map
确保 sentry-cli
已为你的项目配置,并设置环境变量:
.env
SENTRY_ORG=example-org
SENTRY_PROJECT=example-project
SENTRY_AUTH_TOKEN=sntrys_YOUR_TOKEN_HERE
将捆绑包和源映射上传到 Sentry:
npx sentry-cli sourcemaps upload \
--debug-id-reference \
--strip-prefix /path/to/project/root \
index.android.bundle index.android.bundle.map
在将 Sentry Expo 插件和 Sentry Metro 插件添加到应用程序配置后,生成并上传 JavaScript Core 源映射。
要为原生应用程序发布版本生成捆绑包和源映射,请使用以下命令:
# --entry-file node_modules/expo-router/entry.js \
npx expo export:embed \
--entry-file node_modules/expo/AppEntry.js \
--platform android \
--dev false \
--reset-cache \
--bundle-output index.android.bundle \
--sourcemap-output index.android.bundle.map \
--minify true
- 实际命令可能根据你的应用程序配置有所不同。上述命令是 Expo 默认使用的命令。
- 捆绑包和源映射的名称可能会改变生成的调试 ID。
- 对于自定义入口文件路径,需要调整
--entry-file
参数。
确保 sentry-cli
已为你的项目配置,并设置环境变量:
.env
SENTRY_ORG=example-org
SENTRY_PROJECT=example-project
SENTRY_AUTH_TOKEN=sntrys_YOUR_TOKEN_HERE
将捆绑包和源映射上传到 Sentry:
npx sentry-cli sourcemaps upload \
--strip-prefix /path/to/project/root \
index.android.bundle index.android.bundle.map