This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.

设置 EAS 观察

学习如何安装 EAS Observe 并开始从你的生产应用收集性能指标。


用 AI 代理设置 EAS Observe

把这个粘贴到 Claude、Cursor、Codex 或其他代理里。

EAS Observe 追踪你应用在生产环境中的启动性能。本指南将指导你安装库、设置应用以及查看你的第一个指标。

🌐 EAS Observe tracks your app's startup performance in production. This guide walks you through installing the library, setting up your app, and viewing your first metrics.

先决条件

🌐 Prerequisites

先决条件

3 要求

1.

Expo 用户账户

EAS Observe 对任何拥有 Expo 账户的人都可用。你可以在 expo.dev/signup 注册。

2.

Expo SDK 55 或更高版本

EAS Observe 需要 SDK 55 或更高版本。运行 npx expo-doctor 检查你的 SDK 版本,运行 npx expo install --fix 更新依赖。

3.

一个EAS项目

你的应用必须链接到一个 EAS 项目。确保应用配置中的 extra.eas.projectId 包含项目 ID,或通过运行 eas init 创建一个。

1

安装库

🌐 Install the library

确保你正在使用最新版本的 expo,然后安装 expo-observe:

🌐 Make sure you are using the latest version of expo, then install expo-observe:

Terminal
- npx expo install --fix

- npx expo install expo-observe
- yarn expo install --fix

- yarn expo install expo-observe
- pnpm expo install --fix

- pnpm expo install expo-observe
- bun expo install --fix

- bun expo install expo-observe

2

封装你的根布局

🌐 Wrap your root layout

用 AppMetricsRoot(SDK 55)或 ObserveRoot(SDK 56 及以后版本)封装你的根布局。这个高阶组件(HOC)会自动帮你测量首次渲染时间(TTR)。

🌐 Wrap your root layout with AppMetricsRoot (SDK 55) or ObserveRoot (SDK 56 and later). This higher-order component (HOC) automatically measures Time to First Render (TTR) for you.

app/_layout.tsx
import { Stack } from 'expo-router'; import { ObserveRoot } from 'expo-observe'; function RootLayout() { return <Stack />; } export default ObserveRoot.wrap(RootLayout);

3

标记互动

🌐 Mark interactive

当你的应用完全准备好与用户交互时,请调用 markInteractive()。这应该在启动画面后面的任何初始化工作完成后调用,例如:

🌐 Call markInteractive() when your app is fully ready for user interaction. This should be called after any initialization work behind the splash screen completes, such as:

  • 正在检查更新
  • 正在验证用户身份
  • 获取初始数据
  • 动画启动画面
app/_layout.tsx
import { Stack } from 'expo-router'; import * as SplashScreen from 'expo-splash-screen'; import { ObserveRoot, useObserve } from 'expo-observe'; import { useEffect, useState } from 'react'; // Keep the splash screen visible while we fetch resources SplashScreen.preventAutoHideAsync(); function RootLayout() { const [isReady, setIsReady] = useState(false); const { markInteractive } = useObserve(); useEffect(() => { async function prepare() { try { await authenticateUser(); await fetchInitialData(); } catch (e) { console.warn(e); } finally { setIsReady(true); } } prepare(); }, []); useEffect(() => { if (isReady) { SplashScreen.hide(); markInteractive(); } }, [isReady, markInteractive]); if (!isReady) { return null; } return <Stack />; } export default ObserveRoot.wrap(RootLayout);

4

创建新版本

🌐 Create a new build

在安装 expo-observe 并添加了检测工具后,创建你的应用的新版本:

🌐 After installing expo-observe and adding the instrumentation, create a new build of your app:

Terminal
- eas build

5

查看你的指标

🌐 View your metrics

打开你的项目,并在 EAS 仪表板中打开 观察 标签 以查看你的应用指标。

🌐 Open your project and open Observe tab in EAS dashboard to view metrics from your app.

有关过滤、版本比较和会话调查的详细信息,请参阅仪表板指南。

🌐 For details on filtering, release comparison, and session investigation, see the Dashboard guide.

你也可以使用 EAS CLI 从终端查询指标:

🌐 You can also query metrics from the terminal using the EAS CLI:

  • eas observe:versions:列出应用版本及其构建 ID、更新组 ID 和发布日期。对于查找筛选其他命令所需的版本标识符很有用。
  • eas observe:metrics-summary:显示按应用版本分组的聚合性能指标统计(如中位数、p90 和 p99 值)。用它来比较各个版本的整体启动性能。
  • eas observe:metrics:显示按数值排序的各个性能指标事件,包括会话和设备元数据。使用此功能可调查特定的慢会话或异常值。
  • eas observe:routes:显示按路由名称分组的导航指标(冷启动和热启动的首次渲染时间,以及可交互时间)。需要 Expo Router 或 React Navigation 集成。
  • eas observe:session:显示单次会话的完整事件时间线。
  • eas observe:events:显示你的应用通过 Observe.logEvent 发出的各个事件。详情请参阅 用户自定义事件。

使用 --help 运行以下任意命令即可查看可用的标志和参数。有关标志、指标名称和常用工作流程,请参阅 使用 EAS CLI 查询。

🌐 Run any of these commands with --help to see the available flags and arguments. For flags, metric names, and common workflows, see Querying with EAS CLI.

要查看完整的库 API,包括配置选项和所有可用方法,请参阅 expo-observe API 参考。

🌐 For the full library API, including configuration options and all available methods, see the expo-observe API reference.