Repository navigation
feat(telemetry): add last-activity signals to sampled state writes - #47455
Conversation
Surface elapsed-time context on split-state persist events so Sentry can correlate writes with app start, UI open/close, window focus, and SW reloads. Co-authored-by: Cursor <cursoragent@cursor.com>
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
Builds ready [5036243]
⚡ Performance Benchmarks (Total: 🟢 7 pass · 🟡 3 warn · 🔴 3 fail)
Bundle Size Diffs [🚨 Warning! Bundle size has increased!]
|
Omit UI open/close and SW-reload elapsed fields when inactive, and avoid spreading unknown[] into jest mocks so TypeScript lint passes. Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
🟡 Changes recommended
Session-read failures can cause persisted activity history to be overwritten, and sampled-write timing incorrectly includes telemetry latency rather than measuring intervals between successful storage writes.
2 open issues
What changed in this PR
Adds last-activity snapshots to sampled split-state write telemetry, extending existing persistence measurements so analysts can assess activity context without a client-defined idle threshold.
Changes:
- Tracks write, UI, window-focus, and service-worker activity, with session persistence on Manifest V3.
- Attaches elapsed-time signals and reload counts to Sentry state-write spans.
- Adds tests for activity tracking, session restoration, persistence integration, and reporting.
| File | Description |
|---|---|
| shared/lib/telemetry/state-write-reporter.ts | Maps last-activity signals to Sentry attributes. |
| shared/lib/telemetry/state-write-reporter.test.ts | Tests signal reporting and omission of unset values. |
| shared/lib/telemetry/last-activity.ts | Adds activity tracking and session restoration. |
| shared/lib/telemetry/last-activity.test.ts | Tests elapsed times, reloads, and context isolation. |
| shared/lib/stores/persistence-manager.ts | Captures activity snapshots and records successful writes. |
| shared/lib/stores/persistence-manager.test.ts | Tests snapshot integration and write-recording order. |
| app/scripts/lib/setup-initial-state-hooks.test.ts | Updates the write-event fixture with last activity. |
| app/scripts/background.ts | Records UI connections, final UI closures, and window-focus events. |
Review effort: Balanced
Builds ready [4971c90]
⚡ Performance Benchmarks (Total: 🟢 9 pass · 🟡 1 warn · 🔴 3 fail)
Bundle Size Diffs [🚨 Warning! Bundle size has increased!]
|
Keep session writes disabled when storage.session.get throws so later record* calls cannot overwrite an existing lastActivity record. Co-authored-by: Cursor <cursoragent@cursor.com>
Builds ready [45963c1]
⚡ Performance Benchmarks (Total: 🟢 7 pass · 🟡 3 warn · 🔴 3 fail)
Bundle Size Diffs [🚨 Warning! Bundle size has increased!]
|
|
|
No release label on PR. Adding release label release-13.57.0 on PR, as PR was added to branch 13.57.0 when release was cut. |




Description
Implements Option C from ADR 0068 (state-write telemetry idle definition): attach an agnostic last-activity snapshot to each sampled split-state write so analysts can decide what context matters at query time.
Reason: State-write telemetry already records size, controllers, and related measurements. Option C adds a snapshot of what MetaMask did before the write happenned, without baking an arbitrary idle definition into the client.
Solution:
LastActivityand report it on the Sentry state-write event:ms_since_app_startms_since_last_writems_since_ui_openms_since_ui_closedms_since_window_eventlast_service_worker_reloadservice_worker_reload_countChangelog
CHANGELOG entry: null
Related issues
Fixes:
Manual testing steps
ms_since_app_start,ms_since_last_write,ms_since_ui_open,ms_since_ui_closed,ms_since_window_event,last_service_worker_reloadandservice_worker_reload_countproperties are now added tostate.writemetdata of State Persist traces in Sentry.service_worker_reload_countproperty, visit chrome://serviceworker-internals/ , search MetaMask by its ID, and click on "Stop" to restart the service worker.Pre-merge author checklist
Pre-merge reviewer checklist
Made with Cursor
Note
Low Risk
Telemetry-only changes on the persist path with best-effort, fail-open handling; no user-facing behavior or vault logic changes.
Reviewed by Cursor Bugbot for commit 45963c1. Bugbot is set up for automated code reviews on this repo. Configure here.