This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
设置 EAS Observe
编辑页面
了解如何安装 EAS Observe,并开始从你的生产应用中收集性能指标。
使用 AI agent 设置 EAS Observe
将此内容粘贴到 Claude、Cursor、Codex 或其他 agent 中。
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://docs.expo.dev/eas/observe/get-started/.
EAS Observe 跟踪你的应用在生产环境中的启动性能。本指南将带你完成库的安装、应用的设置,以及查看你的第一个指标。
重要 EAS Observe 在 Expo Go 中不可用,因为它依赖于
expo-observe原生库。要使用它,请创建一个开发构建或生产构建。
先决条件
3 requirements
3 requirements
1.
任何拥有 Expo 账号的人都可以使用 EAS Observe。你可以在 expo.dev/signup 注册。
2.
EAS Observe 需要 SDK 55 或更高版本。运行 npx expo-doctor 检查你的 SDK 版本,并运行 npx expo install --fix 更新依赖。
3.
你的应用必须已关联到一个 EAS 项目。请确保应用配置中的 extra.eas.projectId
包含项目 ID,或者通过运行 eas init 创建一个。
2
包裹你的根布局
使用 AppMetricsRoot(SDK 55)或 ObserveRoot(SDK 56 及更高版本)包裹你的根布局。这个高阶组件(HOC)会自动为你测量首次渲染时间(TTR)。
3
标记为可交互
当你的应用完全准备好接受用户交互时,调用 markInteractive()。这应该在闪屏之后的初始化工作全部完成后调用,例如:
- 检查更新
- 用户认证
- 获取初始数据
- 播放闪屏动画
markInteractive()可以在每个会话中安全地调用多次,但只有第一次调用会记录测量结果。如果你的应用有多个入口屏幕(例如引导流程、登录流程或深层链接目标),请在每一个此类屏幕上调用markInteractive。如果你只在一个屏幕上放置它,那么当应用通过深层链接打开另一个屏幕时,就不会记录交互时间(TTI)。
4
创建新构建
在安装 expo-observe 并添加埋点后,请为你的应用创建一个新构建:
默认情况下,从调试构建收集的指标不会被发送。若要在调试构建中测试集成,请参阅在开发环境中启用指标。
5
查看你的指标
打开你的项目,并打开 EAS 控制台中的 Observe 选项卡 来查看来自你的应用的指标。
有关筛选、版本比较和会话调查的详细信息,请参阅 Dashboard 指南。
你也可以使用 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 查询。
有关完整的库 API,包括配置选项和所有可用方法,请参阅 expo-observe API 参考。