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 或其他代理里。
Set up EAS Observe in my Expo project so I can see startup performance from my production app. Work through these steps in order. 1. Identify the SDK version from the `expo` version in package.json, because it decides which steps apply. SDK 56 and later use the `Observe` API. SDK 55 uses the legacy `AppMetrics` names, so the steps marked "SDK 55 only" apply instead of the ones marked "SDK 56 and later" or "SDK 57 and later". Stop and tell me to upgrade if the project is on SDK 54 or earlier, because EAS Observe needs SDK 55 or later. 2. Install or upgrade EAS CLI with `npm install -g eas-cli`, then check that I am logged in with `eas whoami`. Run `eas login` if I am not. 3. Check that the app config has `extra.eas.projectId`. If it is missing, stop and ask me before running `eas init`, because that creates a new project on my account. 4. Run `npx expo install expo-observe`, which installs the version that matches this SDK. 5. Wrap the root layout component and export the wrapped component as the default. The root layout is app/_layout.tsx in an Expo Router project, or the root component the app registers otherwise. This measures time to first render on its own. - Import `ObserveRoot` from `expo-observe` and end the file with `export default ObserveRoot.wrap(RootLayout)`. - SDK 55 only: import `AppMetricsRoot` instead and use `AppMetricsRoot.wrap(RootLayout)`. 6. Call `markInteractive()` once the startup work behind the splash screen has finished. That work includes update checks, authentication, the first data fetch, and the splash screen animation. Call it in an effect that runs after the app sets its ready state and hides the splash screen. - Read `markInteractive` from the `useObserve()` hook inside the component. - SDK 55 only: call `AppMetrics.markInteractive()` instead. There is no hook. - Calling it more than once in a session is safe, because only the first call records the measurement. If the app has more than one entry screen, such as an onboarding flow, a login flow, or a deep link target, call it on every one of them. Otherwise time to interactive is not recorded when the app opens on one of those screens. 7. SDK 56 and later: record per-route navigation metrics, so the dashboard reports render and interactive times per screen instead of app-wide numbers only. - Add `Observe.configure({ integrations: { 'expo-router': true } })` at module scope in the root layout file, above the component, for an Expo Router project. Use `'react-navigation': true` for a project that navigates with React Navigation directly, which needs `@react-navigation/native` 7 or later. - Keep one `Observe.configure()` call and put every option in it, because each call replaces the whole configuration and a later call resets what an earlier one set. The call has to run before any screen mounts, and turning an integration on or off after that throws. - React Navigation only: import from `expo-observe/integrations/react-navigation`. With dynamic configuration, replace the top-level `<NavigationContainer>` with `<ObserveNavigationContainer>`, which takes the same props and forwards the same ref. With static configuration, create the ref with `useNavigationContainerRef()`, pass it to the element `createStaticNavigation()` returns, and wrap that element in `<ObserveNavigationProvider navigationRef={navigationRef}>`. - Move the `markInteractive()` call from step 6 into the screen components, in an effect, because the hook scopes the call to the screen it runs in and a call from outside a screen records nothing. The app-wide time to interactive still comes from that call. Instrument the entry screens, then ask me which other screens should report interactive time. - SDK 57 and later: if route or query parameters in this project carry sensitive values, name those keys in `filteredParams`, as in `{ 'expo-router': { filteredParams: ['userId'] } }`. The integration then leaves them out of the metrics it exports. 8. SDK 57 and later: set up error reporting, which is in preview. Unhandled JavaScript errors are recorded from the moment the package is imported, so the work left is the errors that never reach that handler. - Render errors: replace the `ObserveRoot.wrap()` export from step 5 with the component form and pass a fallback, as in `<ObserveRoot errorBoundaryFallback={<FallbackScreen />}>`, because `wrap()` passes no props. The fallback then renders in place of the app and the error is recorded with its React component stack. To cover one subtree instead of the whole app, wrap that subtree in `<ObserveErrorBoundary>` and pass `fallback` an element or a function that receives `error` and `resetError`. - Handled errors: call `Observe.reportError(error)` in the catch blocks that recover from a failure, such as a failed sync or a failed upload, because those errors reach neither the global handler nor a boundary. Show me the list first if there are more than a few, and keep personal data out of the message, because everything reported is dispatched off-device and shown in the dashboard. - Set `"uploadSourceMaps": true` on the production build profile in eas.json, so the dashboard maps stack traces back to my source files instead of positions in the minified bundle. It needs EAS CLI 22.0.0 or later and a build that runs on EAS Build servers. 9. Stop and ask me: "Instrumentation is in place. Do you want to test it in a development build first?" EAS Observe does not run in Expo Go, so either answer needs a new build. - If I say yes, add `dispatchInDebug: true` to the `Observe.configure()` call, or add that call at module scope if the project has none, because debug builds do not dispatch metrics by default. On SDK 55, call `AppMetrics.configure({ dispatchInDebug: true })` instead. Tell me to remove it before I ship, because debug performance distorts the dashboard. - If I say no, change no configuration. Release builds dispatch by default. 10. Stop and ask me which platform and profile to build, then run `eas build --platform <platform> --profile <profile>`. 11. Tell me to open the Observe tab of the project in the EAS dashboard to see the first metrics, where the Navigation page lists the per-route timings and the Errors page lists the recorded errors. As an alternative, `eas observe:versions` lists the app versions to filter by, `eas observe:metrics-summary` shows median, p90, and p99 startup times per version, `eas observe:metrics` shows individual slow sessions, and `eas observe:routes` shows those per-route timings. Match the package manager this project already uses, and report what you ran. For the EAS Observe get started guide, see https://expo.nodejs.cn/eas/observe/get-started/.
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.
重要 EAS Observe 在 Expo Go 中不可用,因为它依赖于
expo-observe原生库。要使用它,请创建一个 开发构建 或生产构建。
先决条件
🌐 Prerequisites
3 要求
3 要求
1.
EAS Observe 对任何拥有 Expo 账户的人都可用。你可以在 expo.dev/signup 注册。
2.
EAS Observe 需要 SDK 55 或更高版本。运行 npx expo-doctor 检查你的 SDK 版本,运行 npx expo install --fix 更新依赖。
3.
你的应用必须链接到一个 EAS 项目。确保应用配置中的 extra.eas.projectId 包含项目 ID,或通过运行 eas init 创建一个。
1
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.
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:
- 正在检查更新
- 正在验证用户身份
- 获取初始数据
- 动画启动画面
信息
markInteractive()在每个会话中可以安全地被多次调用,但只有第一次调用会记录测量数据。如果你的应用有多个入口界面(例如,新用户引导流程、登录流程或深链接目标),请在每一个界面调用markInteractive。如果只在一个界面放置,当应用通过深链接打开到其他界面时,可交互时间 (TTI) 将不会被记录。
4
创建新版本
🌐 Create a new build
在安装 expo-observe 并添加了检测工具后,创建你的应用的新版本:
🌐 After installing expo-observe and adding the instrumentation, create a new build of your app:
信息 默认情况下,从调试版本收集的指标不会被发送。要在调试版本中测试你的集成,请参见 在开发中启用指标。
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.