JavaScript Core

为使用 JavaScript Core 引擎的 React Native 应用程序上传源映射。

Sentry 的 React Native SDK 开箱即用支持使用 JavaScript Core (JSC) 引擎的应用程序。要在产品中看到可读的堆栈跟踪,需要将源映射上传到 Sentry。本指南解释了如何手动从 JSC 引擎上传源映射。

配置自动上传 source maps 最简单的方法是使用 Sentry Wizard:

Copied
npx @sentry/wizard@latest -i reactNative

要手动上传源映射,首先需要生成源映射和捆绑包。然后编译 Hermes 字节码捆绑包,最后将源映射上传到 Sentry。

首先,在你的 metro.config.js 中添加 Sentry React Native Metro 插件:

Copied
const { getDefaultConfig } = require("@react-native/metro-config");
const { withSentryConfig } = require("@sentry/react-native/metro");

const config = getDefaultConfig(__dirname);
module.exports = withSentryConfig(config);

生成 React Native Packager (Metro) 捆绑包和源映射:

Copied
npx react-native bundle \
  --dev false \
  --minify true \
  --platform android \
  --entry-file index.js \
  --reset-cache \
  --bundle-output index.android.bundle \
  --sourcemap-output index.android.bundle.map

确保 sentry-cli 已为你的项目配置,并设置环境变量:

.env
Copied
SENTRY_ORG=example-org
SENTRY_PROJECT=example-project
SENTRY_AUTH_TOKEN=sntrys_YOUR_TOKEN_HERE

将捆绑包和源映射上传到 Sentry:

Copied
node_modules/@sentry/cli/bin/sentry-cli sourcemaps upload \
  --strip-prefix /path/to/project/root \
  index.android.bundle index.android.bundle.map