使用 Sentry

有关安装和配置 Sentry 以进行崩溃报告的指南。


Sentry 是一个崩溃报告平台,可让你实时了解生产部署,并提供重现和修复崩溃的信息。

¥Sentry is a crash reporting platform that provides you with real-time insight into production deployments with info to reproduce and fix crashes.

它会通知你用户在使用你的应用时遇到的异常或错误,并在网络仪表板上为你组织它们。自动报告的异常包括堆栈跟踪、设备信息、版本和其他相关上下文。你还可以提供特定于你的应用的其他上下文,例如当前路由和用户 ID。

¥It notifies you of exceptions or errors that your users run into while using your app and organizes them for you on a web dashboard. Reported exceptions include stacktraces, device info, version, and other relevant context automatically. You can also provide additional context that is specific to your application such as the current route and user id.

你将学到什么

¥What you'll learn

本指南涵盖了将 Sentry 与你的 Expo 项目集成的三个主要方面:

¥This guide covers three main aspects of integrating Sentry with your Expo projects:

Platform compatibility

Android DeviceAndroid EmulatoriOS DeviceiOS SimulatorWeb

安装和配置 Sentry

¥Install and configure Sentry

1

Sign up for a Sentry account and create a project

Before proceeding with installing Sentry, you'll need to make sure you have created a Sentry account and project:

1.1

Sign up for Sentry (the free tier supports up to 5,000 events per month), and create a project in your Dashboard. Take note of your organization slug, project name, and DSN as you'll need them later:

  • organization slug is available in your Organization settings tab
  • project name is available in your project's Settings > Projects tab (find it in the list)
  • DSN is available in your project's Settings > Projects > Project name > Under SDK Setup section > Client Keys (DSN) tab.

1.2

Go to the Developer Settings > Auth Tokens page and create a new Organization Auth Token. The token is automatically scoped for Source Map Upload and Release Creation. Save it.

Once you have each of these: organization slug, project name, DSN, and auth token, you're all set to proceed.

2

Use the Sentry wizard to set up your project

The easiest way to set up Sentry in your Expo project is to use the Sentry wizard. This tool will automatically configure your project with the right settings.

Run the following command in your project directory:

Terminal
npx @sentry/wizard@latest -i reactNative

The wizard will:

  • Install the required dependencies
  • Configure your project to use Sentry
  • Set up the Metro configuration automatically
  • Add the necessary initialization code to your app

Follow the prompts in the wizard to complete the setup process. The wizard will guide you to log in to your Sentry account and fetch all the correct information regarding your project.

3

Verify the configuration

Create a new release build of your app and verify that it uploads source maps correctly. You may want to add a button in your app to test that it is working and sourcemaps are wired up as expected, for example:

import { Button } from 'react-native';

// Inside some component
<Button title="Press me" onPress={() => { throw new Error('Hello, again, Sentry!'); }}/>

Usage with EAS Build

Ensure that SENTRY_AUTH_TOKEN is set in your build environment, and Sentry will automatically upload source maps for you. If you use environment variables rather than properties in your app config, ensure that those are set as well.

Using the above instructions, no additional work is needed to integrate Sentry into your project when using EAS Build.

Usage with EAS Update

After running eas update, upload the source maps to Sentry:

Terminal
# Pass in the "dist" directory generated by `eas update` to the upload script
npx sentry-expo-upload-sourcemaps dist

That's it! Errors for your updates will now be properly symbolicated in Sentry.

Do you want to publish an update and the sourcemaps in one command?

You can chain the commands together with && to publish an update and upload the sourcemaps in one step:

Terminal
eas update --branch <branch> && npx sentry-expo-upload-sourcemaps dist

Sentry integration with EAS dashboard

The Sentry integration with Expo allows you to view crash reports and Session Replays for your Expo app deployments directly within your EAS dashboard. This integration provides a direct link to Sentry stack traces with full context, session replays, and debugging capabilities.

Install

Sentry owner, manager, or admin permissions are required to install this integration.
  1. Log in to you Expo account and open Account settings > Overview.
  2. Under Connections and click Connect next to Sentry.
  3. Log in to your Sentry account and accept the integration into your organization. You will be redirected back to Account settings.

Link your project

After connecting your accounts, you need to link your EAS Project to your Sentry Project:

  1. Open Projects > [Your Project] > Configuration > Project settings in EAS.
  2. Click Link and select your Sentry Project from the dropdown.

Usage

To see your Sentry data in EAS dashboard, open **Projects > [Your Project] > Updates > Deployments >

[Deployment]** 用于从发布版本查看 Sentry 数据。

¥[Deployment]** to view Sentry data from a Release.

通过此集成,你可以:

¥With this integration, you can:

  • 直接在 EAS 仪表板中查看崩溃报告

    ¥View crash reports directly in your EAS dashboard

  • 访问会话回放,查看错误发生前的具体情况

    ¥Access Session Replays to see exactly what happened before an error occurred

  • 获取包含完整上下文的详细堆栈跟踪

    ¥Get detailed stack traces with full context

  • 在 EAS 和 Sentry 之间无缝导航以进行调试

    ¥Navigate seamlessly between EAS and Sentry for debugging

了解有关 Sentry 的更多信息

¥Learn more about Sentry

Sentry 的作用不仅仅是捕获致命错误,还可以从其 JavaScript 使用 文档中了解有关如何使用 Sentry 的更多信息。

¥Sentry does more than just catch fatal errors, learn more about how to use Sentry from their JavaScript usage documentation.