Skip to content

feat: init perps sentry implementation - #41528

Merged
gambinish merged 26 commits into
mainfrom
perps/add-sentry-integration
Apr 9, 2026
Merged

feat: init perps sentry implementation#41528
gambinish merged 26 commits into
mainfrom
perps/add-sentry-integration

Conversation

@gambinish

@gambinish gambinish commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

Description

Wires up Sentry observability for the Perps feature across the background controller and UI layers.

The controller's createLogger now uses Sentry's withScope to attach structured context to errors — every perps error gets a feature:perps tag plus optional tags, context, and extras from the controller. The createTracer stubs are replaced with real startSpanManual span tracking and setMeasurement support.

On the UI side, two new hooks are added:

usePerpsMeasurement — measures time from component mount to data-ready and reports it as a Sentry custom measurement. Used on the Perps tab and market detail page.

usePerpsLifecycleBreadcrumbs — adds breadcrumbs for popup open/hide/close events, which show up in the breadcrumb trail of any Sentry error captured while the user is in Perps.
Also adds translatePerpsError / handlePerpsError — a utility that maps PerpsErrorCode values and raw API error strings (via regex patterns) to i18n keys, so error messages surfaced to users are translated and meaningful rather than raw codes.

Changelog

CHANGELOG entry: Wires up sentry events

Related issues

Fixes:

Manual testing steps

Set SENTRY_DSN_DEV, ENABLE_SETTINGS_PAGE_DEV_OPTIONS=true, and DEBUG=metamask:sentry:* in .metamaskrc
Enable MetaMetrics in Settings > Security & Privacy
Navigate to the Perps tab and wait for data to load (fires PerpsTabLoaded measurement)
Throw a test error via Settings > Developer Options
In Sentry Issues, confirm the event has feature:perps tag and perps.lifecycle breadcrumbs

Note: you may need to setup a custom sentry dashboard for testing purposes, as the main dev dashboard gets 429 rate limit errors.

Screenshots/Recordings

Screenshot 2026-04-07 at 12 13 48 PM

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Note

Medium Risk
Adds Sentry logging/tracing/measurements and changes Perps UI error/toast messaging to use new translation logic, which could affect what users see during failures. While primarily observability, it touches controller infrastructure and several Perps flows, so regressions would be user-visible.

Overview
Adds first-pass Sentry instrumentation for Perps across controller infrastructure and UI. The Perps controller logger now reports errors via Sentry withScope with a default feature=perps tag plus optional tags/context/extras, and the tracer now creates/ends Sentry spans (with bounded pending-span tracking) and forwards setMeasurement.

Improves Perps error UX by translating controller/API failures into i18n messages. Introduces translatePerpsError/handlePerpsError (code + regex-pattern mapping) and updates close/reverse/order/withdraw flows to use these translated messages/fallbacks; adds new Perps i18n strings for common failure cases.

Adds UI performance/lifecycle breadcrumbs for debugging. New hooks usePerpsMeasurement (reports load timings) and usePerpsLifecycleBreadcrumbs (popup open/hidden/closing breadcrumbs) are wired into Perps views/layout, with extensive new/updated tests around Sentry integration and translated error outputs.

Reviewed by Cursor Bugbot for commit 35298ff. Bugbot is set up for automated code reviews on this repo. Configure here.

@metamaskbot metamaskbot added the team-perps Perps team label Apr 7, 2026
@metamaskbotv2

metamaskbotv2 Bot commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

✨ Files requiring CODEOWNER review ✨

🔑 @MetaMask/accounts-engineers (1 files, +3 -5)
  • 📁 ui/
    • 📁 components/
      • 📁 multichain/
        • 📁 account-overview/
          • 📄 account-overview-tabs.tsx +3 -5

👨‍🔧 @MetaMask/core-extension-ux (1 files, +3 -5)
  • 📁 ui/
    • 📁 components/
      • 📁 multichain/
        • 📁 account-overview/
          • 📄 account-overview-tabs.tsx +3 -5

👨‍🔧 @MetaMask/perps (23 files, +1917 -227)
  • 📁 app/
    • 📁 scripts/
      • 📁 controllers/
        • 📁 perps/
          • 📄 infrastructure.test.ts +410 -3
          • 📄 infrastructure.ts +86 -8
  • 📁 ui/
    • 📁 components/
      • 📁 app/
        • 📁 perps/
          • 📁 close-position/
            • 📄 close-position-modal.test.tsx +62 -1
            • 📄 close-position-modal.tsx +6 -9
          • 📁 reverse-position/
            • 📄 reverse-position-modal.test.tsx +75 -6
            • 📄 reverse-position-modal.tsx +5 -5
          • 📁 utils/
            • 📄 translate-perps-error.test.ts +302 -0
            • 📄 translate-perps-error.ts +233 -0
            • 📄 perps-view-stream-boundary.tsx +2 -0
            • 📄 perps-view.tsx +4 -0
    • 📁 hooks/
      • 📁 perps/
        • 📄 index.ts +2 -0
        • 📄 usePerpsLifecycleBreadcrumbs.test.ts +133 -0
        • 📄 usePerpsLifecycleBreadcrumbs.ts +56 -0
        • 📄 usePerpsMeasurement.test.ts +132 -0
        • 📄 usePerpsMeasurement.ts +32 -0
    • 📁 pages/
      • 📁 perps/
        • 📄 perps-layout.test.tsx +61 -0
        • 📄 perps-layout.tsx +2 -0
        • 📄 perps-market-detail-page.test.tsx +160 -146
        • 📄 perps-market-detail-page.tsx +6 -0
        • 📄 perps-order-entry-page.test.tsx +65 -8
        • 📄 perps-order-entry-page.tsx +10 -38
        • 📄 perps-withdraw-page.test.tsx +58 -0
        • 📄 perps-withdraw-page.tsx +15 -3

@metamaskbotv2

metamaskbotv2 Bot commented Apr 7, 2026

Copy link
Copy Markdown
Contributor
Builds ready [1009523]
⚡ Performance Benchmarks (Total: 🟢 7 pass · 🟡 12 warn · 🔴 0 fail)

Baseline (latest main): f34f804 | Date: 9/10/58222 | Pipeline: 24103671042 | Baseline logs

Interaction Benchmarks · Samples: 5
Benchmarkchrome-browserify
loadNewAccount🟡 [Show logs]
confirmTx🟡 [Show logs]
bridgeUserActions🟡 [Show logs]

📈 Results compared to the previous 5 runs on main

  • loadNewAccount/load_new_account: -18%
  • loadNewAccount/total: -18%
  • bridgeUserActions/bridge_load_asset_picker: -54%
  • bridgeUserActions/bridge_search_token: -22%
  • bridgeUserActions/total: -21%

🌐 Core Web Vitals — 🟢 good · 🟡 needs improvement · 🔴 poor (web.dev thresholds)

  • 🟡 loadNewAccount/FCP: p75 2.4s
  • 🟡 confirmTx/FCP: p75 2.4s
  • 🟡 bridgeUserActions/FCP: p75 2.4s
Startup Benchmarks · Samples: 100
Benchmarkchrome-browserifychrome-webpackfirefox-browserifyfirefox-webpack
startupStandardHome🟢 [Show logs]🟢 [Show logs]🟢 [Show logs]🟢 [Show logs]
startupPowerUserHome🟡 [Show logs]🟡 [Show logs]🟡 [Show logs]🟡 [Show logs]

📈 Results compared to the previous 5 runs on main

  • startupStandardHome/uiStartup: -10%
  • startupStandardHome/load: -12%
  • startupStandardHome/domContentLoaded: -14%
  • startupStandardHome/domInteractive: +10%
  • startupStandardHome/backgroundConnect: +12%
  • startupStandardHome/initialActions: -38%
  • startupStandardHome/loadScripts: -17%
  • startupStandardHome/numNetworkReqs: -21%
  • startupPowerUserHome/backgroundConnect: +108%
  • startupPowerUserHome/setupStore: +17%
  • startupStandardHome/uiStartup: -15%
  • startupStandardHome/load: -14%
  • startupStandardHome/domContentLoaded: -13%
  • startupStandardHome/firstPaint: -11%
  • startupStandardHome/backgroundConnect: -34%
  • startupStandardHome/firstReactRender: -20%
  • startupStandardHome/loadScripts: -13%
  • startupStandardHome/numNetworkReqs: -29%
  • startupPowerUserHome/domInteractive: -23%
  • startupPowerUserHome/firstPaint: -11%
  • startupStandardHome/domInteractive: -59%
  • startupStandardHome/initialActions: -38%
  • startupStandardHome/numNetworkReqs: -18%
  • startupPowerUserHome/uiStartup: -12%
  • startupPowerUserHome/domInteractive: -15%
  • startupPowerUserHome/backgroundConnect: -38%
  • startupPowerUserHome/setupStore: +49%
  • startupStandardHome/domInteractive: -30%
  • startupStandardHome/initialActions: +11%
  • startupStandardHome/setupStore: -54%
  • startupStandardHome/numNetworkReqs: -11%
  • startupPowerUserHome/domInteractive: -14%
  • startupPowerUserHome/backgroundConnect: -26%
  • startupPowerUserHome/firstReactRender: -11%
  • startupPowerUserHome/setupStore: +24%
  • startupPowerUserHome/numNetworkReqs: -26%

🌐 Core Web Vitals — 🟢 good · 🟡 needs improvement · 🔴 poor (web.dev thresholds)

  • 🔴 startupPowerUserHome/INP: p75 720ms
  • 🔴 startupPowerUserHome/INP: p75 696ms
  • 🟡 startupPowerUserHome/LCP: p75 3.5s
  • 🟡 startupPowerUserHome/LCP: p75 3.6s
User Journey Benchmarks · Samples: 5 · mock API
Benchmarkchrome-browserify
onboardingImportWallet🟢 [Show logs]
onboardingNewWallet🟢 [Show logs]
assetDetails🟡 [Show logs]
solanaAssetDetails🟡 [Show logs]
importSrpHome🟡 [Show logs]
sendTransactions🟡 [Show logs]
swap🟡 [Show logs]

📈 Results compared to the previous 5 runs on main

  • onboardingImportWallet/srpButtonToSrpForm: -84%
  • onboardingImportWallet/metricsToWalletReadyScreen: -17%
  • onboardingImportWallet/doneButtonToHomeScreen: -75%
  • onboardingImportWallet/openAccountMenuToAccountListLoaded: +33%
  • onboardingImportWallet/total: -40%
  • onboardingNewWallet/srpButtonToPwForm: -78%
  • onboardingNewWallet/skipBackupToMetricsScreen: -68%
  • onboardingNewWallet/agreeButtonToOnboardingSuccess: -29%
  • onboardingNewWallet/doneButtonToAssetList: -21%
  • onboardingNewWallet/total: -23%
  • assetDetails/assetClickToPriceChart: -71%
  • assetDetails/total: -71%
  • solanaAssetDetails/assetClickToPriceChart: -69%
  • solanaAssetDetails/total: -69%
  • importSrpHome/openAccountMenuAfterLogin: -75%
  • importSrpHome/homeAfterImportWithNewWallet: -69%
  • importSrpHome/total: -60%
  • sendTransactions/openSendPageFromHome: -20%
  • sendTransactions/selectTokenToSendFormLoaded: -28%
  • sendTransactions/reviewTransactionToConfirmationPage: +39%
  • sendTransactions/total: +36%
  • swap/openSwapPageFromHome: -96%
  • swap/fetchAndDisplaySwapQuotes: +31%
  • swap/total: +11%

🌐 Core Web Vitals — 🟢 good · 🟡 needs improvement · 🔴 poor (web.dev thresholds)

  • 🟡 assetDetails/INP: p75 216ms
  • 🟡 assetDetails/FCP: p75 2.5s
  • 🟡 solanaAssetDetails/FCP: p75 2.5s
  • 🟡 importSrpHome/INP: p75 208ms
  • 🟡 importSrpHome/FCP: p75 2.5s
  • 🟡 sendTransactions/INP: p75 256ms
  • 🟡 sendTransactions/FCP: p75 2.5s
  • 🟡 swap/FCP: p75 2.5s
Dapp Page Load Benchmarks · Samples: 100
Benchmarkchrome-browserify
dappPageLoad🟢 [Show logs]
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 678 Bytes (0.01%)
  • ui: 2.74 KiB (0.03%)
  • common: 20 Bytes (0%)

@gambinish
gambinish marked this pull request as ready for review April 7, 2026 22:18
@gambinish
gambinish requested a review from a team as a code owner April 7, 2026 22:18
Comment thread ui/components/app/perps/utils/translate-perps-error.ts Outdated
Comment thread ui/components/app/perps/utils/translate-perps-error.ts
Comment thread app/scripts/controllers/perps/infrastructure.ts
@metamaskbotv2

metamaskbotv2 Bot commented Apr 7, 2026

Copy link
Copy Markdown
Contributor
Builds ready [74a33b3]
⚡ Performance Benchmarks (Total: 🟢 7 pass · 🟡 12 warn · 🔴 0 fail)

Baseline (latest main): f34f804 | Date: 9/10/58222 | Pipeline: 24108791299 | Baseline logs

Interaction Benchmarks · Samples: 5
Benchmarkchrome-browserify
loadNewAccount🟡 [Show logs]
confirmTx🟡 [Show logs]
bridgeUserActions🟡 [Show logs]

📈 Results compared to the previous 5 runs on main

  • bridgeUserActions/bridge_load_asset_picker: -43%
  • bridgeUserActions/bridge_search_token: -29%
  • bridgeUserActions/total: -29%

🌐 Core Web Vitals — 🟢 good · 🟡 needs improvement · 🔴 poor (web.dev thresholds)

  • 🟡 loadNewAccount/FCP: p75 2.4s
  • 🟡 confirmTx/FCP: p75 2.5s
  • 🟡 bridgeUserActions/FCP: p75 2.5s
Startup Benchmarks · Samples: 100
Benchmarkchrome-browserifychrome-webpackfirefox-browserifyfirefox-webpack
startupStandardHome🟢 [Show logs]🟢 [Show logs]🟢 [Show logs]🟢 [Show logs]
startupPowerUserHome
🟡 uiStartup
[Show logs]
🟡 [Show logs]🟡 [Show logs]🟡 [Show logs]

📈 Results compared to the previous 5 runs on main

  • startupStandardHome/uiStartup: -11%
  • startupStandardHome/load: -13%
  • startupStandardHome/domContentLoaded: -15%
  • startupStandardHome/backgroundConnect: +12%
  • startupStandardHome/initialActions: -38%
  • startupStandardHome/loadScripts: -18%
  • startupStandardHome/numNetworkReqs: -21%
  • startupPowerUserHome/backgroundConnect: +141%
  • startupPowerUserHome/initialActions: +100%
  • startupPowerUserHome/setupStore: +17%
  • startupPowerUserHome/numNetworkReqs: -55%
  • startupStandardHome/uiStartup: -12%
  • startupStandardHome/load: -11%
  • startupStandardHome/domContentLoaded: -11%
  • startupStandardHome/firstPaint: +10%
  • startupStandardHome/backgroundConnect: -30%
  • startupStandardHome/firstReactRender: -20%
  • startupStandardHome/loadScripts: -11%
  • startupStandardHome/numNetworkReqs: -29%
  • startupPowerUserHome/domInteractive: -22%
  • startupStandardHome/domInteractive: -56%
  • startupStandardHome/initialActions: -38%
  • startupStandardHome/numNetworkReqs: -18%
  • startupPowerUserHome/uiStartup: -13%
  • startupPowerUserHome/domInteractive: -13%
  • startupPowerUserHome/backgroundConnect: -35%
  • startupStandardHome/uiStartup: -11%
  • startupStandardHome/domInteractive: -35%
  • startupStandardHome/backgroundConnect: -20%
  • startupStandardHome/initialActions: -44%
  • startupStandardHome/setupStore: -57%
  • startupStandardHome/numNetworkReqs: -18%
  • startupPowerUserHome/backgroundConnect: -31%

🌐 Core Web Vitals — 🟢 good · 🟡 needs improvement · 🔴 poor (web.dev thresholds)

  • 🔴 startupPowerUserHome/INP: p75 696ms
  • 🔴 startupPowerUserHome/INP: p75 656ms
  • 🟡 startupPowerUserHome/LCP: p75 3.5s
  • 🟡 startupPowerUserHome/INP: p75 240ms
  • 🟡 startupPowerUserHome/LCP: p75 3.5s
User Journey Benchmarks · Samples: 5 · mock API
Benchmarkchrome-browserify
onboardingImportWallet🟢 [Show logs]
onboardingNewWallet🟢 [Show logs]
assetDetails🟡 [Show logs]
solanaAssetDetails🟡 [Show logs]
importSrpHome🟡 [Show logs]
sendTransactions🟡 [Show logs]
swap🟡 [Show logs]

📈 Results compared to the previous 5 runs on main

  • onboardingImportWallet/srpButtonToSrpForm: -85%
  • onboardingImportWallet/metricsToWalletReadyScreen: -45%
  • onboardingImportWallet/doneButtonToHomeScreen: -75%
  • onboardingImportWallet/openAccountMenuToAccountListLoaded: +23%
  • onboardingImportWallet/total: -41%
  • onboardingNewWallet/srpButtonToPwForm: -79%
  • onboardingNewWallet/skipBackupToMetricsScreen: -68%
  • onboardingNewWallet/doneButtonToAssetList: -37%
  • onboardingNewWallet/total: -36%
  • assetDetails/assetClickToPriceChart: -76%
  • assetDetails/total: -76%
  • solanaAssetDetails/assetClickToPriceChart: -71%
  • solanaAssetDetails/total: -71%
  • importSrpHome/openAccountMenuAfterLogin: -74%
  • importSrpHome/homeAfterImportWithNewWallet: -70%
  • importSrpHome/total: -61%
  • sendTransactions/selectTokenToSendFormLoaded: -28%
  • sendTransactions/reviewTransactionToConfirmationPage: +34%
  • sendTransactions/total: +31%
  • swap/openSwapPageFromHome: -96%
  • swap/fetchAndDisplaySwapQuotes: +31%
  • swap/total: +12%

🌐 Core Web Vitals — 🟢 good · 🟡 needs improvement · 🔴 poor (web.dev thresholds)

  • 🟡 assetDetails/INP: p75 224ms
  • 🟡 assetDetails/FCP: p75 2.5s
  • 🟡 solanaAssetDetails/FCP: p75 2.5s
  • 🟡 importSrpHome/INP: p75 224ms
  • 🟡 importSrpHome/FCP: p75 2.4s
  • 🟡 sendTransactions/INP: p75 256ms
  • 🟡 sendTransactions/FCP: p75 2.5s
  • 🟡 swap/FCP: p75 2.5s
Dapp Page Load Benchmarks · Samples: 100
Benchmarkchrome-browserify
dappPageLoad🟢 [Show logs]
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 678 Bytes (0.01%)
  • ui: 2.74 KiB (0.03%)
  • common: 95 Bytes (0%)

@metamaskbotv2

metamaskbotv2 Bot commented Apr 8, 2026

Copy link
Copy Markdown
Contributor
Builds ready [eb70694]
⚡ Performance Benchmarks (Total: 🟢 7 pass · 🟡 12 warn · 🔴 0 fail)

Baseline (latest main): f34f804 | Date: 9/10/58222 | Pipeline: 24110512574 | Baseline logs

Interaction Benchmarks · Samples: 5
Benchmarkchrome-browserify
loadNewAccount🟡 [Show logs]
confirmTx🟡 [Show logs]
bridgeUserActions🟡 [Show logs]

📈 Results compared to the previous 5 runs on main

  • loadNewAccount/load_new_account: -41%
  • loadNewAccount/total: -41%
  • bridgeUserActions/bridge_load_asset_picker: -65%
  • bridgeUserActions/bridge_search_token: -28%
  • bridgeUserActions/total: -35%

🌐 Core Web Vitals — 🟢 good · 🟡 needs improvement · 🔴 poor (web.dev thresholds)

  • 🟡 loadNewAccount/FCP: p75 2.2s
  • 🟡 confirmTx/FCP: p75 2.0s
  • 🟡 bridgeUserActions/FCP: p75 2.0s
Startup Benchmarks · Samples: 100
Benchmarkchrome-browserifychrome-webpackfirefox-browserifyfirefox-webpack
startupStandardHome🟢 [Show logs]🟢 [Show logs]🟢 [Show logs]🟢 [Show logs]
startupPowerUserHome🟡 [Show logs]🟡 [Show logs]🟡 [Show logs]🟡 [Show logs]

📈 Results compared to the previous 5 runs on main

  • startupStandardHome/domContentLoaded: -11%
  • startupStandardHome/domInteractive: +10%
  • startupStandardHome/backgroundConnect: +16%
  • startupStandardHome/initialActions: -38%
  • startupStandardHome/loadScripts: -14%
  • startupPowerUserHome/uiStartup: -16%
  • startupPowerUserHome/backgroundConnect: +42%
  • startupPowerUserHome/setupStore: +17%
  • startupStandardHome/uiStartup: -13%
  • startupStandardHome/load: -12%
  • startupStandardHome/domContentLoaded: -12%
  • startupStandardHome/firstPaint: +17%
  • startupStandardHome/backgroundConnect: -31%
  • startupStandardHome/firstReactRender: -20%
  • startupStandardHome/loadScripts: -12%
  • startupStandardHome/numNetworkReqs: -29%
  • startupPowerUserHome/domInteractive: -17%
  • startupPowerUserHome/numNetworkReqs: -21%
  • startupStandardHome/domInteractive: -58%
  • startupStandardHome/initialActions: +25%
  • startupStandardHome/numNetworkReqs: -18%
  • startupPowerUserHome/uiStartup: -12%
  • startupPowerUserHome/backgroundConnect: -29%
  • startupStandardHome/domInteractive: -36%
  • startupStandardHome/backgroundConnect: -12%
  • startupStandardHome/initialActions: +11%
  • startupStandardHome/setupStore: -51%
  • startupStandardHome/numNetworkReqs: -11%
  • startupPowerUserHome/backgroundConnect: -28%
  • startupPowerUserHome/firstReactRender: -11%
  • startupPowerUserHome/numNetworkReqs: -40%

🌐 Core Web Vitals — 🟢 good · 🟡 needs improvement · 🔴 poor (web.dev thresholds)

  • 🔴 startupPowerUserHome/INP: p75 632ms
  • 🔴 startupPowerUserHome/INP: p75 640ms
  • 🟡 startupPowerUserHome/LCP: p75 3.5s
  • 🟡 startupPowerUserHome/INP: p75 248ms
  • 🟡 startupPowerUserHome/LCP: p75 3.5s
User Journey Benchmarks · Samples: 5 · mock API
Benchmarkchrome-browserify
onboardingImportWallet🟢 [Show logs]
onboardingNewWallet🟢 [Show logs]
assetDetails🟡 [Show logs]
solanaAssetDetails🟡 [Show logs]
importSrpHome🟡 [Show logs]
sendTransactions🟡 [Show logs]
swap🟡 [Show logs]

📈 Results compared to the previous 5 runs on main

  • onboardingImportWallet/srpButtonToSrpForm: -84%
  • onboardingImportWallet/metricsToWalletReadyScreen: -41%
  • onboardingImportWallet/doneButtonToHomeScreen: -76%
  • onboardingImportWallet/openAccountMenuToAccountListLoaded: +34%
  • onboardingImportWallet/total: -40%
  • onboardingNewWallet/srpButtonToPwForm: -79%
  • onboardingNewWallet/skipBackupToMetricsScreen: -70%
  • onboardingNewWallet/doneButtonToAssetList: -39%
  • onboardingNewWallet/total: -36%
  • assetDetails/assetClickToPriceChart: -72%
  • assetDetails/total: -72%
  • solanaAssetDetails/assetClickToPriceChart: -63%
  • solanaAssetDetails/total: -63%
  • importSrpHome/openAccountMenuAfterLogin: -73%
  • importSrpHome/homeAfterImportWithNewWallet: -74%
  • importSrpHome/total: -62%
  • sendTransactions/openSendPageFromHome: -18%
  • sendTransactions/selectTokenToSendFormLoaded: -33%
  • sendTransactions/reviewTransactionToConfirmationPage: +34%
  • sendTransactions/total: +31%
  • swap/openSwapPageFromHome: -96%
  • swap/fetchAndDisplaySwapQuotes: +31%
  • swap/total: +11%

🌐 Core Web Vitals — 🟢 good · 🟡 needs improvement · 🔴 poor (web.dev thresholds)

  • 🟡 assetDetails/INP: p75 224ms
  • 🟡 assetDetails/FCP: p75 2.6s
  • 🟡 assetDetails/LCP: p75 2.6s
  • 🟡 solanaAssetDetails/FCP: p75 2.7s
  • 🟡 importSrpHome/INP: p75 216ms
  • 🟡 importSrpHome/FCP: p75 2.4s
  • 🟡 sendTransactions/INP: p75 216ms
  • 🟡 sendTransactions/FCP: p75 2.5s
  • 🟡 swap/FCP: p75 2.5s
Dapp Page Load Benchmarks · Samples: 100
Benchmarkchrome-browserify
dappPageLoad🟢 [Show logs]
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 834 Bytes (0.01%)
  • ui: 10.5 KiB (0.12%)
  • common: 264 Bytes (0%)

@geositta geositta left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tracer's bounded span tracking with FIFO eviction looks solid, and the observability primitives are separated cleanly. I am requesting changes on two points: the lifecycle breadcrumbs are mounted too low and drop coverage on non-home Perps routes, and the market-detail loaded measurement fires before the page is actually ready. I also don't see any integration of the new error translation module. I left comments on each.

Comment thread ui/components/app/perps/perps-view.tsx Outdated
Comment thread ui/pages/perps/perps-market-detail-page.tsx Outdated
Comment thread ui/components/app/perps/utils/translate-perps-error.ts
Comment thread ui/components/app/perps/utils/translate-perps-error.ts Outdated
Comment thread app/scripts/controllers/perps/infrastructure.ts
Comment thread app/scripts/controllers/perps/infrastructure.test.ts
Comment thread ui/components/app/perps/utils/translate-perps-error.ts
geositta
geositta previously approved these changes Apr 9, 2026

@geositta geositta left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks for addressing my points.

michalconsensys
michalconsensys previously approved these changes Apr 9, 2026
@metamaskbotv2

metamaskbotv2 Bot commented Apr 9, 2026

Copy link
Copy Markdown
Contributor
Builds ready [d40b54c]
⚡ Performance Benchmarks (Total: 🟢 7 pass · 🟡 12 warn · 🔴 0 fail)

Baseline (latest main): f34f804 | Date: 9/10/58222 | Pipeline: 24199605378 | Baseline logs

Interaction Benchmarks · Samples: 5
Benchmarkchrome-browserify
loadNewAccount🟡 [Show logs]
confirmTx🟡 [Show logs]
bridgeUserActions🟡 [Show logs]

📈 Results compared to the previous 5 runs on main

  • bridgeUserActions/bridge_search_token: +40%
  • bridgeUserActions/total: +17%

🌐 Core Web Vitals — 🟢 good · 🟡 needs improvement · 🔴 poor (web.dev thresholds)

  • 🟡 loadNewAccount/FCP: p75 2.4s
  • 🟡 confirmTx/FCP: p75 2.4s
  • 🟡 bridgeUserActions/FCP: p75 2.4s
Startup Benchmarks · Samples: 100
Benchmarkchrome-browserifychrome-webpackfirefox-browserifyfirefox-webpack
startupStandardHome🟢 [Show logs]🟢 [Show logs]🟢 [Show logs]🟢 [Show logs]
startupPowerUserHome🟡 [Show logs]🟡 [Show logs]🟡 [Show logs]🟡 [Show logs]

📈 Results compared to the previous 5 runs on main

  • startupStandardHome/domContentLoaded: -11%
  • startupStandardHome/backgroundConnect: +14%
  • startupStandardHome/firstReactRender: -13%
  • startupStandardHome/initialActions: -38%
  • startupStandardHome/loadScripts: -13%
  • startupPowerUserHome/backgroundConnect: +130%
  • startupPowerUserHome/setupStore: +17%
  • startupPowerUserHome/numNetworkReqs: -17%
  • startupStandardHome/uiStartup: -13%
  • startupStandardHome/load: -13%
  • startupStandardHome/domContentLoaded: -13%
  • startupStandardHome/backgroundConnect: -32%
  • startupStandardHome/firstReactRender: -28%
  • startupStandardHome/loadScripts: -12%
  • startupStandardHome/setupStore: -14%
  • startupStandardHome/numNetworkReqs: -29%
  • startupPowerUserHome/domInteractive: -25%
  • startupPowerUserHome/numNetworkReqs: +25%
  • startupStandardHome/domInteractive: -59%
  • startupStandardHome/initialActions: +25%
  • startupStandardHome/setupStore: +21%
  • startupStandardHome/numNetworkReqs: -13%
  • startupPowerUserHome/uiStartup: -13%
  • startupPowerUserHome/domInteractive: -19%
  • startupPowerUserHome/backgroundConnect: -43%
  • startupStandardHome/domInteractive: -49%
  • startupStandardHome/backgroundConnect: -24%
  • startupStandardHome/initialActions: -44%
  • startupStandardHome/setupStore: -57%
  • startupStandardHome/numNetworkReqs: -18%
  • startupPowerUserHome/domInteractive: -22%
  • startupPowerUserHome/backgroundConnect: -33%

🌐 Core Web Vitals — 🟢 good · 🟡 needs improvement · 🔴 poor (web.dev thresholds)

  • 🔴 startupPowerUserHome/INP: p75 680ms
  • 🔴 startupPowerUserHome/INP: p75 744ms
  • 🟡 startupPowerUserHome/LCP: p75 3.3s
  • 🟡 startupPowerUserHome/LCP: p75 3.6s
User Journey Benchmarks · Samples: 5 · mock API
Benchmarkchrome-browserify
onboardingImportWallet🟢 [Show logs]
onboardingNewWallet🟢 [Show logs]
assetDetails🟡 [Show logs]
solanaAssetDetails🟡 [Show logs]
importSrpHome🟡 [Show logs]
sendTransactions🟡 [Show logs]
swap🟡 [Show logs]

📈 Results compared to the previous 5 runs on main

  • onboardingImportWallet/srpButtonToSrpForm: -85%
  • onboardingImportWallet/metricsToWalletReadyScreen: -40%
  • onboardingImportWallet/doneButtonToHomeScreen: -75%
  • onboardingImportWallet/openAccountMenuToAccountListLoaded: +23%
  • onboardingImportWallet/total: -42%
  • onboardingNewWallet/srpButtonToPwForm: -77%
  • onboardingNewWallet/skipBackupToMetricsScreen: -68%
  • onboardingNewWallet/agreeButtonToOnboardingSuccess: -27%
  • onboardingNewWallet/doneButtonToAssetList: -26%
  • onboardingNewWallet/total: -27%
  • assetDetails/assetClickToPriceChart: -34%
  • assetDetails/total: -34%
  • solanaAssetDetails/assetClickToPriceChart: -58%
  • solanaAssetDetails/total: -58%
  • importSrpHome/openAccountMenuAfterLogin: -73%
  • importSrpHome/homeAfterImportWithNewWallet: -70%
  • importSrpHome/total: -61%
  • sendTransactions/selectTokenToSendFormLoaded: -22%
  • sendTransactions/reviewTransactionToConfirmationPage: +34%
  • sendTransactions/total: +31%
  • swap/openSwapPageFromHome: -97%
  • swap/fetchAndDisplaySwapQuotes: +31%
  • swap/total: +11%

🌐 Core Web Vitals — 🟢 good · 🟡 needs improvement · 🔴 poor (web.dev thresholds)

  • 🟡 assetDetails/INP: p75 208ms
  • 🟡 assetDetails/FCP: p75 2.6s
  • 🟡 solanaAssetDetails/FCP: p75 2.6s
  • 🟡 importSrpHome/FCP: p75 2.5s
  • 🟡 sendTransactions/INP: p75 256ms
  • 🟡 sendTransactions/FCP: p75 2.5s
  • 🟡 swap/FCP: p75 2.5s
Dapp Page Load Benchmarks · Samples: 100
Benchmarkchrome-browserify
dappPageLoad🟢 [Show logs]
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 834 Bytes (0.01%)
  • ui: 8.58 KiB (0.1%)
  • common: 1.01 KiB (0.01%)

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit c989573. Configure here.

Comment thread ui/pages/perps/perps-order-entry-page.tsx
@metamaskbotv2

metamaskbotv2 Bot commented Apr 9, 2026

Copy link
Copy Markdown
Contributor
Builds ready [c989573]
⚡ Performance Benchmarks (Total: 🟢 7 pass · 🟡 12 warn · 🔴 0 fail)

Baseline (latest main): f34f804 | Date: 9/10/58222 | Pipeline: 24207296265 | Baseline logs

Interaction Benchmarks · Samples: 5
Benchmarkchrome-browserify
loadNewAccount🟡 [Show logs]
confirmTx🟡 [Show logs]
bridgeUserActions🟡 [Show logs]

📈 Results compared to the previous 5 runs on main

  • bridgeUserActions/bridge_load_asset_picker: -33%
  • bridgeUserActions/bridge_search_token: -18%
  • bridgeUserActions/total: -20%

🌐 Core Web Vitals — 🟢 good · 🟡 needs improvement · 🔴 poor (web.dev thresholds)

  • 🟡 loadNewAccount/FCP: p75 2.5s
  • 🟡 confirmTx/FCP: p75 2.6s
  • 🟡 bridgeUserActions/FCP: p75 2.5s
Startup Benchmarks · Samples: 100
Benchmarkchrome-browserifychrome-webpackfirefox-browserifyfirefox-webpack
startupStandardHome🟢 [Show logs]🟢 [Show logs]🟢 [Show logs]🟢 [Show logs]
startupPowerUserHome🟡 [Show logs]🟡 [Show logs]🟡 [Show logs]🟡 [Show logs]

📈 Results compared to the previous 5 runs on main

  • startupStandardHome/domContentLoaded: -12%
  • startupStandardHome/firstPaint: +13%
  • startupStandardHome/backgroundConnect: +13%
  • startupStandardHome/firstReactRender: -17%
  • startupStandardHome/initialActions: -38%
  • startupStandardHome/loadScripts: -14%
  • startupPowerUserHome/domInteractive: -15%
  • startupPowerUserHome/backgroundConnect: +113%
  • startupStandardHome/uiStartup: -14%
  • startupStandardHome/load: -13%
  • startupStandardHome/domContentLoaded: -13%
  • startupStandardHome/backgroundConnect: -31%
  • startupStandardHome/firstReactRender: -20%
  • startupStandardHome/loadScripts: -12%
  • startupStandardHome/numNetworkReqs: -29%
  • startupPowerUserHome/domInteractive: -17%
  • startupPowerUserHome/numNetworkReqs: -22%
  • startupStandardHome/domInteractive: -54%
  • startupStandardHome/initialActions: +25%
  • startupStandardHome/setupStore: +21%
  • startupStandardHome/numNetworkReqs: -18%
  • startupPowerUserHome/backgroundConnect: -31%
  • startupPowerUserHome/setupStore: +18%
  • startupStandardHome/domInteractive: -27%
  • startupStandardHome/initialActions: -44%
  • startupStandardHome/setupStore: -54%
  • startupPowerUserHome/backgroundConnect: -29%
  • startupPowerUserHome/firstReactRender: +10%

🌐 Core Web Vitals — 🟢 good · 🟡 needs improvement · 🔴 poor (web.dev thresholds)

  • 🔴 startupPowerUserHome/INP: p75 744ms
  • 🔴 startupPowerUserHome/INP: p75 696ms
  • 🟡 startupPowerUserHome/LCP: p75 3.5s
  • 🟡 startupPowerUserHome/INP: p75 472ms
  • 🟡 startupPowerUserHome/LCP: p75 3.6s
User Journey Benchmarks · Samples: 5 · mock API
Benchmarkchrome-browserify
onboardingImportWallet🟢 [Show logs]
onboardingNewWallet🟢 [Show logs]
assetDetails🟡 [Show logs]
solanaAssetDetails🟡 [Show logs]
importSrpHome🟡 [Show logs]
sendTransactions🟡 [Show logs]
swap🟡 [Show logs]

📈 Results compared to the previous 5 runs on main

  • onboardingImportWallet/srpButtonToSrpForm: -85%
  • onboardingImportWallet/metricsToWalletReadyScreen: -44%
  • onboardingImportWallet/doneButtonToHomeScreen: -75%
  • onboardingImportWallet/openAccountMenuToAccountListLoaded: +33%
  • onboardingImportWallet/total: -40%
  • onboardingNewWallet/srpButtonToPwForm: -79%
  • onboardingNewWallet/skipBackupToMetricsScreen: -71%
  • onboardingNewWallet/agreeButtonToOnboardingSuccess: -32%
  • onboardingNewWallet/doneButtonToAssetList: -37%
  • onboardingNewWallet/total: -36%
  • assetDetails/assetClickToPriceChart: -43%
  • assetDetails/total: -43%
  • solanaAssetDetails/assetClickToPriceChart: -67%
  • solanaAssetDetails/total: -67%
  • importSrpHome/openAccountMenuAfterLogin: -76%
  • importSrpHome/homeAfterImportWithNewWallet: -70%
  • importSrpHome/total: -60%
  • sendTransactions/openSendPageFromHome: -20%
  • sendTransactions/selectTokenToSendFormLoaded: -29%
  • sendTransactions/reviewTransactionToConfirmationPage: +33%
  • sendTransactions/total: +31%
  • swap/openSwapPageFromHome: -94%
  • swap/fetchAndDisplaySwapQuotes: +32%
  • swap/total: +12%

🌐 Core Web Vitals — 🟢 good · 🟡 needs improvement · 🔴 poor (web.dev thresholds)

  • 🟡 assetDetails/INP: p75 216ms
  • 🟡 assetDetails/FCP: p75 2.5s
  • 🟡 solanaAssetDetails/FCP: p75 2.5s
  • 🟡 importSrpHome/INP: p75 224ms
  • 🟡 importSrpHome/FCP: p75 2.5s
  • 🟡 sendTransactions/INP: p75 240ms
  • 🟡 sendTransactions/FCP: p75 2.6s
  • 🟡 swap/FCP: p75 2.5s
Dapp Page Load Benchmarks · Samples: 100
Benchmarkchrome-browserify
dappPageLoad🟢 [Show logs]
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 813 Bytes (0.01%)
  • ui: -25.64 KiB (-0.3%)
  • common: 2.3 KiB (0.02%)

@geositta geositta left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found a new followup while verifying the breadcrumb change. My earlier comment focused on the routed Perps tree and suggested PerpsLayout as the right mount point for that path which you fixed.

However I noticed there is also an embedded Perps mount in ui/components/multichain/account-overview/account-overview-tabs.tsx that goes through perps-view-stream-boundary.tsx rather than PerpsLayout, so breadcrumb coverage is still not complete across every Perps surface.

If we want complete coverage across both mount paths, the simplest followup is to attach usePerpsLifecycleBreadcrumbs() in PerpsViewStreamBoundary as well.

@sonarqubecloud

sonarqubecloud Bot commented Apr 9, 2026

Copy link
Copy Markdown

@metamaskbotv2

metamaskbotv2 Bot commented Apr 9, 2026

Copy link
Copy Markdown
Contributor
Builds ready [35298ff]
⚡ Performance Benchmarks (Total: 🟢 7 pass · 🟡 12 warn · 🔴 0 fail)

Baseline (latest main): f34f804 | Date: 9/10/58222 | Pipeline: 24212383565 | Baseline logs

Interaction Benchmarks · Samples: 5
Benchmarkchrome-browserify
loadNewAccount🟡 [Show logs]
confirmTx🟡 [Show logs]
bridgeUserActions🟡 [Show logs]

📈 Results compared to the previous 5 runs on main

  • bridgeUserActions/bridge_load_asset_picker: -13%
  • bridgeUserActions/bridge_search_token: +15%

🌐 Core Web Vitals — 🟢 good · 🟡 needs improvement · 🔴 poor (web.dev thresholds)

  • 🟡 loadNewAccount/FCP: p75 2.5s
  • 🟡 confirmTx/FCP: p75 2.5s
  • 🟡 bridgeUserActions/FCP: p75 2.5s
Startup Benchmarks · Samples: 100
Benchmarkchrome-browserifychrome-webpackfirefox-browserifyfirefox-webpack
startupStandardHome🟢 [Show logs]🟢 [Show logs]🟢 [Show logs]🟢 [Show logs]
startupPowerUserHome
🟡 uiStartup
[Show logs]
🟡 [Show logs]🟡 [Show logs]🟡 [Show logs]

📈 Results compared to the previous 5 runs on main

  • startupStandardHome/domContentLoaded: -11%
  • startupStandardHome/backgroundConnect: +16%
  • startupStandardHome/initialActions: -38%
  • startupStandardHome/loadScripts: -13%
  • startupStandardHome/setupStore: +20%
  • startupPowerUserHome/domInteractive: -10%
  • startupPowerUserHome/backgroundConnect: +113%
  • startupPowerUserHome/setupStore: +11%
  • startupPowerUserHome/numNetworkReqs: -52%
  • startupStandardHome/uiStartup: -13%
  • startupStandardHome/load: -13%
  • startupStandardHome/domContentLoaded: -12%
  • startupStandardHome/backgroundConnect: -32%
  • startupStandardHome/firstReactRender: -20%
  • startupStandardHome/loadScripts: -12%
  • startupStandardHome/numNetworkReqs: -29%
  • startupPowerUserHome/domInteractive: -25%
  • startupPowerUserHome/numNetworkReqs: +13%
  • startupStandardHome/domInteractive: -60%
  • startupStandardHome/initialActions: -38%
  • startupStandardHome/setupStore: +14%
  • startupStandardHome/numNetworkReqs: -18%
  • startupPowerUserHome/domInteractive: +16%
  • startupPowerUserHome/backgroundConnect: -34%
  • startupPowerUserHome/setupStore: -17%
  • startupStandardHome/uiStartup: -11%
  • startupStandardHome/load: -11%
  • startupStandardHome/domContentLoaded: -11%
  • startupStandardHome/domInteractive: -30%
  • startupStandardHome/backgroundConnect: -19%
  • startupStandardHome/initialActions: -44%
  • startupStandardHome/loadScripts: -10%
  • startupStandardHome/setupStore: -63%
  • startupStandardHome/numNetworkReqs: -18%
  • startupPowerUserHome/uiStartup: -14%
  • startupPowerUserHome/domInteractive: -20%
  • startupPowerUserHome/backgroundConnect: -38%

🌐 Core Web Vitals — 🟢 good · 🟡 needs improvement · 🔴 poor (web.dev thresholds)

  • 🔴 startupPowerUserHome/INP: p75 696ms
  • 🔴 startupPowerUserHome/INP: p75 672ms
  • 🟡 startupPowerUserHome/LCP: p75 3.5s
  • 🟡 startupPowerUserHome/LCP: p75 3.4s
User Journey Benchmarks · Samples: 5 · mock API
Benchmarkchrome-browserify
onboardingImportWallet🟢 [Show logs]
onboardingNewWallet🟢 [Show logs]
assetDetails🟡 [Show logs]
solanaAssetDetails🟡 [Show logs]
importSrpHome🟡 [Show logs]
sendTransactions🟡 [Show logs]
swap🟡 [Show logs]

📈 Results compared to the previous 5 runs on main

  • onboardingImportWallet/srpButtonToSrpForm: -84%
  • onboardingImportWallet/metricsToWalletReadyScreen: -22%
  • onboardingImportWallet/doneButtonToHomeScreen: -75%
  • onboardingImportWallet/openAccountMenuToAccountListLoaded: +33%
  • onboardingImportWallet/total: -42%
  • onboardingNewWallet/srpButtonToPwForm: -78%
  • onboardingNewWallet/skipBackupToMetricsScreen: -66%
  • onboardingNewWallet/agreeButtonToOnboardingSuccess: -11%
  • onboardingNewWallet/doneButtonToAssetList: -25%
  • onboardingNewWallet/total: -26%
  • solanaAssetDetails/assetClickToPriceChart: -62%
  • solanaAssetDetails/total: -62%
  • importSrpHome/openAccountMenuAfterLogin: -70%
  • importSrpHome/homeAfterImportWithNewWallet: -70%
  • importSrpHome/total: -60%
  • sendTransactions/openSendPageFromHome: -26%
  • sendTransactions/selectTokenToSendFormLoaded: -28%
  • sendTransactions/reviewTransactionToConfirmationPage: +33%
  • sendTransactions/total: +30%
  • swap/openSwapPageFromHome: -97%
  • swap/fetchAndDisplaySwapQuotes: +31%
  • swap/total: +11%

🌐 Core Web Vitals — 🟢 good · 🟡 needs improvement · 🔴 poor (web.dev thresholds)

  • 🟡 assetDetails/INP: p75 232ms
  • 🟡 assetDetails/FCP: p75 2.5s
  • 🟡 solanaAssetDetails/FCP: p75 2.5s
  • 🟡 importSrpHome/INP: p75 224ms
  • 🟡 importSrpHome/FCP: p75 2.6s
  • 🟡 sendTransactions/INP: p75 224ms
  • 🟡 sendTransactions/FCP: p75 2.4s
  • 🟡 swap/FCP: p75 2.5s
Dapp Page Load Benchmarks · Samples: 100
Benchmarkchrome-browserify
dappPageLoad🟢 [Show logs]
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 1.03 KiB (0.02%)
  • ui: -24.49 KiB (-0.29%)
  • common: 9.05 KiB (0.07%)

@gambinish
gambinish added this pull request to the merge queue Apr 9, 2026
Merged via the queue into main with commit 185cd97 Apr 9, 2026
207 of 208 checks passed
@gambinish
gambinish deleted the perps/add-sentry-integration branch April 9, 2026 22:08
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 9, 2026
@metamaskbot metamaskbot added the release-13.28.0 Issue or pull request that will be included in release 13.28.0 label Apr 9, 2026
@MajorLift

MajorLift commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

🧪 Validation Run

Verdict: 📋 every emission this PR adds has a named bound — but two of the background bounds work by calling end() on a span whose operation has not finished, and an early-ended span reaches Sentry as a completed one — Claim: every Sentry emission this PR adds is bounded, and by what. head 35298ff · 2026-08-02 · instrumentation-bound check

Note

Trial run of the MetaMask evidence skills
feedback welcome, on the finding or on whether this format is useful to a reviewer.
Not a review verdict; nothing here blocks the PR.

Each emission site the diff adds, read out of the committed tree at the PR head, next to whatever it is that limits how often it fires. Counted over the whole PR, base 8508068 to head, rather than the tip commit:

Ran to completion (exit 0) — read the output, no verdict asserted

Claim under test: every Sentry emission this PR adds is bounded, and by what

$ bash -c B=850806819e5d6d65ea5a632ff38fc03dc72c1827; H=35298ff56ddc38ad4d67ca53630f4fb91653c2c9
I=app/scripts/controllers/perps/infrastructure.ts
git fetch -q --depth=1 origin $B
echo "== production files this PR touches (tests excluded) =="
git diff --stat $B $H -- "*.ts" "*.tsx" ":(exclude)*.test.*" ":(exclude)test/*"
echo
echo "== usePerpsMeasurement: what bounds how often it reports =="
git show $H:ui/hooks/perps/usePerpsMeasurement.ts | cat -n | sed -n 18,32p
echo
echo "== every measurement name reaching Sentry from a production call site =="
git grep -hoE "usePerpsMeasurement[(][^,]+" $H -- "*.tsx" "*.ts" ":(exclude)*.test.*" | sort -u
echo
echo "== usePerpsLifecycleBreadcrumbs: listeners registered, and removed =="
git grep -nE "addEventListener|removeEventListener" $H -- ui/hooks/perps/usePerpsLifecycleBreadcrumbs.ts
echo
echo "== the background spans, which no component lifecycle bounds =="
git show $H:$I | cat -n | sed -n 80p
git show $H:$I | cat -n | sed -n 104,137p
echo
echo "== and how a span ends =="
git show $H:$I | cat -n | sed -n 139,155p
== production files this PR touches (tests excluded) ==
 app/scripts/controllers/perps/infrastructure.ts    |  94 ++++++++-
 .../perps/close-position/close-position-modal.tsx  |  15 +-
 .../app/perps/perps-view-stream-boundary.tsx       |   2 +
 ui/components/app/perps/perps-view.tsx             |   4 +
 .../reverse-position/reverse-position-modal.tsx    |  10 +-
 .../app/perps/utils/translate-perps-error.ts       | 233 +++++++++++++++++++++
 .../account-overview/account-overview-tabs.tsx     |   8 +-
 ui/hooks/perps/index.ts                            |   2 +
 ui/hooks/perps/usePerpsLifecycleBreadcrumbs.ts     |  56 +++++
 ui/hooks/perps/usePerpsMeasurement.ts              |  32 +++
 ui/pages/perps/perps-layout.tsx                    |   2 +
 ui/pages/perps/perps-market-detail-page.tsx        |   6 +
 ui/pages/perps/perps-order-entry-page.tsx          |  48 +----
 ui/pages/perps/perps-withdraw-page.tsx             |  18 +-
 14 files changed, 462 insertions(+), 68 deletions(-)

== usePerpsMeasurement: what bounds how often it reports ==
    18	  const mountTimeRef = useRef<number>(performance.now());
    19	  const hasReportedRef = useRef(false);
    20	
    21	  useEffect(() => {
    22	    if (isReady && !hasReportedRef.current) {
    23	      hasReportedRef.current = true;
    24	      const duration = performance.now() - mountTimeRef.current;
    25	      globalThis.sentry?.setMeasurement?.(
    26	        measurementName,
    27	        duration,
    28	        'millisecond',
    29	      );
    30	    }
    31	  }, [isReady, measurementName]);
    32	}

== every measurement name reaching Sentry from a production call site ==
usePerpsMeasurement('PerpsTabLoaded'

== usePerpsLifecycleBreadcrumbs: listeners registered, and removed ==
35298ff56ddc38ad4d67ca53630f4fb91653c2c9:ui/hooks/perps/usePerpsLifecycleBreadcrumbs.ts:48:    document.addEventListener('visibilitychange', handleVisibilityChange);
35298ff56ddc38ad4d67ca53630f4fb91653c2c9:ui/hooks/perps/usePerpsLifecycleBreadcrumbs.ts:49:    window.addEventListener('beforeunload', handleBeforeUnload);
35298ff56ddc38ad4d67ca53630f4fb91653c2c9:ui/hooks/perps/usePerpsLifecycleBreadcrumbs.ts:52:      document.removeEventListener('visibilitychange', handleVisibilityChange);
35298ff56ddc38ad4d67ca53630f4fb91653c2c9:ui/hooks/perps/usePerpsLifecycleBreadcrumbs.ts:53:      window.removeEventListener('beforeunload', handleBeforeUnload);

== the background spans, which no component lifecycle bounds ==
    80	const MAX_PENDING_SPANS = 50;
   104	      const key = `${params.name}:${params.id}`;
   105	
   106	      // End any existing span with the same key before overwriting to avoid
   107	      // leaking the old span reference when trace() is called twice with the
   108	      // same name/id pair.
   109	      const existing = pendingSpans.get(key);
   110	      if (existing) {
   111	        existing.end();
   112	        pendingSpans.delete(key);
   113	      }
   114	
   115	      // Evict the oldest pending span when the map is at capacity so the map
   116	      // cannot grow unboundedly over long browser sessions.
   117	      if (pendingSpans.size >= MAX_PENDING_SPANS) {
   118	        const oldestKey = pendingSpans.keys().next().value;
   119	        if (oldestKey !== undefined) {
   120	          pendingSpans.get(oldestKey)?.end();
   121	          pendingSpans.delete(oldestKey);
   122	        }
   123	      }
   124	
   125	      startSpanManual(
   126	        {
   127	          name: params.name,
   128	          op: params.op,
   129	          attributes: { ...params.tags, ...params.data },
   130	        },
   131	        (span: {
   132	          setAttribute: (key: string, value: PerpsTraceValue) => void;
   133	          end: () => void;
   134	        }) => {
   135	          pendingSpans.set(key, span);
   136	        },
   137	      );

== and how a span ends ==
   139	    endTrace: (params: {
   140	      name: PerpsTraceName;
   141	      id: string;
   142	      data?: Record<string, PerpsTraceValue>;
   143	    }) => {
   144	      const key = `${params.name}:${params.id}`;
   145	      const pending = pendingSpans.get(key);
   146	      if (pending) {
   147	        if (params.data) {
   148	          for (const [attrKey, attrValue] of Object.entries(params.data)) {
   149	            pending.setAttribute(attrKey, attrValue);
   150	          }
   151	        }
   152	        pending.end();
   153	        pendingSpans.delete(key);
   154	      }
   155	    },

Produced by capture.sh, not transcribed. head 35298ff56ddc38ad4d67ca53630f4fb91653c2c9 · 0 tracked changes · node v22.23.1 · Python 3.12.3 · yarn.lock d9aec55c5f23bb54. Run: https://github.com/MajorLift/metamask-skills/actions/runs/30768628349 — logs and artifacts attached there.

Follows from the above

  • usePerpsMeasurement reports at most once per mount: the flag at 23 is set before the write at 25 and never cleared, so later isReady transitions do not re-report.
  • One measurement name reaches Sentry from production code, so cardinality does not grow with usage — the quota cost is bounded by mounts, not by names.
  • The breadcrumb hook registers two listeners and removes both, so breadcrumb volume tracks popup lifecycles rather than renders.
  • The background spans are bounded by something else entirely: a map capped at the constant on 80 (checked at 117), and the eviction of any span sharing a name/id key (109–113). Both keep the map small by ending a span whose work is still in flight.
  • A span ended at 111 or 120 is closed by the same call as one ended at 152. Downstream there is nothing to tell them apart — the evicted one arrives as a short, successful span.

Open for review: for the trace names this PR introduces, is there a path where trace() starts a span and endTrace() is never reached — an order abandoned, a popup closed mid-flight? Those are the spans eviction will close, and they will read as fast successes rather than as missing.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-13.28.0 Issue or pull request that will be included in release 13.28.0 size-XL team-perps Perps team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants