@embrace-io/react-native

中文文档
7.2.0发布于 2026/10/09Apache-2.0TypeScriptCommonJS构建来源已验证近 30 天下载 3.7万

A React Native wrapper for the Embrace SDK

原始使用文档
文档目录10 节
  1. Add the JavaScript library
  2. Native Setup
  3. Using the Expo config plugin
  4. Running the setup scripts
  5. Manually
  6. Sourcing the Embrace iOS SDK from SPM
  7. Initialize the Embrace SDK
  8. Uploading source maps
  9. Additional features
  10. Troubleshooting

React Native Embrace

Embrace gathers the information needed to identify issues and measure performance automatically upon integration. The following React Native guide provides simple instruction on how to call the relevant functions so teams can be provided much needed additional context (logs and user info) and measure the timing of key areas of their app explicitly (spans).

For additional info please refer to the React Native Guide.

[!IMPORTANT] Starting the native SDK from JavaScript (sdkConfig.ios, sdkConfig.exporters) and @embrace-io/react-native-otlp are deprecated and will be removed in the next major release. Start Embrace in native code as described in Native Setup and Start Embrace SDK in the native side.

Requirements

Only an Embrace App ID and an Embrace API Token.

If you need an App ID and API Token, Go to our dashboard to create an account.

Integration

Add the JavaScript library

npm:

npm install @embrace-io/react-native

yarn:

yarn add @embrace-io/react-native

For iOS you will also need to install or update pods for the application:

cd ios && pod install --repo-update

Native Setup

There are 3 options for applying the native side changes required by the SDK: using our Expo config plugin, using our setup script, or applying them manually. Each options is described below.

Using the Expo config plugin

If you are using Expo's prebuild system to manage your native files you can make use of our config plugin. In your app.json configure the plugin with your Embrace application IDs and symbol upload API token:

    "plugins": [
        ...
        
        [
            "@embrace-io/react-native/lib/app.plugin.js",
            {
                "androidAppId": "__ANDROID_APP_ID__",
                "iOSAppId": "__IOS_APP_ID__",
                "apiToken": "__SYMBOL_UPLOAD_API_TOKEN__"
            }
        ]
    ],

Refer to EmbraceProps for the full set properties available to configure the plugin.

To source the Embrace iOS SDK from Swift Package Manager instead of CocoaPods, set the iOSUseSPM property. See Sourcing the Embrace iOS SDK from SPM below.

The next time you run npx expo prebuild the native Android and iOS files should be updated with the changes required by the Embrace SDK. Note that there are other customizations and advanced features of the SDK such as OTLP Export which will still require manual editing of native files, at the moment the config plugin only covers this initial SDK setup.

Running the setup scripts

The JavaScript Embrace SDK ships with a setup script to modify the files in your project to add the native dependencies. The setup scripts can be found in your node_modules folder at node_modules/@embrace-io/react-native/lib/scripts/setup.

node node_modules/@embrace-io/react-native/lib/scripts/setup/installAndroid.js
node node_modules/@embrace-io/react-native/lib/scripts/setup/installIos.js

Manually

To apply the native setup manually refer to this section of our guide to add the native SDKs, then follow the steps to start the Embrace SDK in the native side.

Sourcing the Embrace iOS SDK from SPM

By default the Embrace iOS SDK is installed as a CocoaPods dependency, but can be configured to source the iOS SDK from Swift Package Manager instead. SPM mode uses React Native's spm_dependency helper, which requires React Native >= 0.75 and USE_FRAMEWORKS=dynamic.

If you are using the Expo config plugin, set the iOSUseSPM property and add expo-build-properties with ios.useFrameworks: "dynamic", see the plugin's README for a full example.

Otherwise opt in when installing pods:

EMBRACE_USE_SPM=1 USE_FRAMEWORKS=dynamic pod install

Initialize the Embrace SDK

The Embrace SDK should be started in native code before initialize is called. The Expo config plugin and the setup scripts in Native Setup do this for you; if you set up manually, see Start Embrace SDK in the native side.

Then call initialize once, at the top level of your application, to set up tracking on the JS side:

import React, { useEffect } from 'react'
import { initialize } from '@embrace-io/react-native';

const App = () => {
  useEffect(() => {
    const initEmbrace = async () => {
      try {
        const isStarted = await initialize({ trackUnhandledRejections: true });

        if (isStarted) {
          // do something
        }
      } catch {
        console.log("Error initializing Embrace SDK");
      }
    };

    initEmbrace();
  }, []); // you should only initialize the Embrace SDK once.

  // regular content of the application
  return (
    ...
  );
}

export default App

Uploading source maps

The Embrace SDK allows you to view both native and JavaScript stack traces for crashes and error logs. Refer to our guide on uploading symbol files.

Additional features

Additional features for our SDK are kept in other packages to allow you to include just the dependencies for the ones you are using and to keep your overall bundle size smaller. Once this core package is installed you can check out the documentation in our Feature Reference to learn more about these additional packages. The various screens in our Test Harness also provide examples of how these packages can be used with the core SDK.

Troubleshooting

Please refer to our complete integration guide. If you continue to run into issues please contact us directly or reach out in our Community Slack

版本与发布记录

@embrace-io/react-native 共发布 36 个版本,首次发布于 2024/01/17;过去 12 个月发布了 9 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
7.2.0latest2026/10/091 个月前
7.1.02026/09/012 个月前
7.0.02026/07/134 个月前
6.7.12026/07/074 个月前
6.7.02026/06/115 个月前
6.6.02026/03/128 个月前

关于 @embrace-io/react-native 的常见问题

@embrace-io/react-native 是什么?

A React Native wrapper for the Embrace SDK

如何安装 @embrace-io/react-native?

在项目目录运行 npm install @embrace-io/react-native,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react-native(>=0.56.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@embrace-io/react-native 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@embrace-io/react-native 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@embrace-io/react-native 可以商用吗?

@embrace-io/react-native 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@embrace-io/react-native 的下载量有多少?

根据 npm 官方下载统计,@embrace-io/react-native 在 2026/10/14 – 2026/11/12 这 30 天内被下载 37,217 次,日均约 1,241 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@embrace-io/react-native 还在维护吗?

最新版本 7.2.0 发布于 2026/10/09(1 个月前);至今共发布 36 个版本,其中过去 12 个月发布了 9 个;首次发布于 2024/01/17。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。