Skip to content

chore: add advanced charts traces cp-7.76.0#29497

Merged
sahar-fehri merged 10 commits into
mainfrom
chore/add-advanced-charts-traces
May 6, 2026
Merged

chore: add advanced charts traces cp-7.76.0#29497
sahar-fehri merged 10 commits into
mainfrom
chore/add-advanced-charts-traces

Conversation

@sahar-fehri

@sahar-fehri sahar-fehri commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

Description

Adds Sentry performance traces for token-overview advanced chart visibility (time from series change until skeleton clears), with separate trace types for dashboards to distinguish initial load / asset or currency changes from time-range-only updates.
Also fixes a bug in metrics consent detection during early Sentry initialization.

Changes

Advanced Chart Performance Tracing

AdvancedChart component:

  • Added optional onSkeletonHidden callback that fires once when loading/layout settles and the chart is ready
  • Guarded by refs to reset when series key or HTML content changes
    PriceAdvanced component:
  • Starts trace() when ohlcvSeriesKey changes
  • Ends trace via endTrace() when:
    • Skeleton hides (chart ready)
    • Chart error occurs
    • Trace is superseded by a newer series
    • Falls back to legacy chart
  • getAdvancedChartVisibilityTraceRequest() selects appropriate TraceName and TraceOperation based on what changed:
    • Same asset + currency with only range change → TokenOverviewAdvancedChartTimeRangeVisible trace
    • Otherwise → TokenOverviewAdvancedChartInitialVisible trace
      trace.ts:
  • Added new TraceName values:
    • TokenOverviewAdvancedChartInitialVisible - for initial load or asset/currency changes
    • TokenOverviewAdvancedChartTimeRangeVisible - for time range selector changes only
  • Added new TraceOperation values:
    • token_overview.advanced_chart - initial load or asset/currency change
    • token_overview.advanced_chart_time_range - time range change only

Metrics Consent Fix

Problem:
The original implementation attempted to read from analytics.isEnabled() during Sentry initialization in index.js:45. However, this occurs before Engine and Redux are initialized, causing analytics.isEnabled() to incorrectly return false even for opted-in users (it checks in-memory state that doesn't exist yet).
Solution:
hasMetricsConsent() now reads directly from AnalyticsController's persisted state in FilesystemStorage (persist:AnalyticsController) before falling back to the legacy METRICS_OPT_IN storage key. This approach:

  • Works before Engine/Redux initialization (FilesystemStorage is always available)
  • Reads the actual persisted opt-in value from disk ({"optedIn": true/false})
  • Follows the same pattern as ControllerStorage.getAllPersistedState() in persistConfig/index.ts
  • Avoids dependency on deprecated METRICS_OPT_IN as the primary source
    MetaMetricsAndDataCollectionSection:
  • Calls updateCachedConsent() when user toggles analytics participation
  • Ensures in-memory consent cache stays synchronized with AnalyticsController state

Changelog

CHANGELOG entry: Adds tracing for advanced charts

Related issues

Fixes: https://consensyssoftware.atlassian.net/browse/ASSETS-3129

Manual testing steps

Feature: Advanced Chart Performance Tracing

  Scenario: user opens token details and chart loads successfully
    Given the user is on the home screen

    When user taps on a token to open token details
    Then a single "Starting sampled root span" log appears for "Token Overview Advanced Chart Initial Visible"
    And a single "Finishing" log appears for the same span ID
    And no duplicate "Token Overview" traces appear

  Scenario: user navigates back before chart finishes loading
    Given the user is on token details with the chart still loading (skeleton visible)

    When user quickly navigates back to the home screen
    Then a "Finishing" log appears for the "Token Overview Advanced Chart Initial Visible" span
    And the finish log appears after the navigation back (after "[UserInteraction]" log)

  Scenario: user navigates back after chart has loaded
    Given the user is on token details and the chart has fully loaded

    When user navigates back to the home screen
    Then no "Token Overview" trace logs appear during navigation back

  Scenario: user changes time range on the chart
    Given the user is on token details with the chart loaded on 1D range

    When user taps on the 1W time range selector
    Then a "Finishing" log appears for the previous "Token Overview Advanced Chart Initial Visible" span
    And a new "Starting sampled root span" log appears for "Token Overview Advanced Chart Time Range Visible"
    And a "Finishing" log appears for the new span when the chart reloads
How to verify locally:
1. Enable Sentry trace logging by filtering console output for "Tracing"
2. Navigate to a token's details screen
3. Confirm you see exactly ONE "Starting sampled root span" for
   "Token Overview Advanced Chart Initial Visible" followed by ONE
   "Finishing" log for the same span ID
4. Navigate back — confirm no additional trace start/finish for that span
5. Re-enter the token, change time range — confirm the old trace ends
   with superseded and a new "Time Range Visible" trace starts and finishes

Screenshots/Recordings

Before

After

Pre-merge author checklist

Performance checks (if applicable)

  • I've tested on Android
    • Ideally on a mid-range device; emulator is acceptable
  • I've tested with a power user scenario
    • Use these power-user SRPs to import wallets with many accounts and tokens
  • I've instrumented key operations with Sentry traces for production performance metrics

For performance guidelines and tooling, see the Performance Guide.

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 new Sentry tracing lifecycle hooks around the token overview advanced chart and changes how metrics consent is determined during early app startup, which could affect whether performance data is captured or suppressed.

Overview
Adds Sentry performance traces for token overview advanced chart visibility, starting a trace on ohlcvSeriesKey changes and ending it when the chart skeleton disappears, errors, is superseded by a newer request, falls back to the legacy chart, or unmounts (including assetId and truncated error details).

Extends AdvancedChart with an onSkeletonHidden callback that fires once when the native skeleton overlay is removed (resetting on series/HTML reload), and adds new TraceName/TraceOperation constants to distinguish initial/asset changes vs time-range-only updates.

Fixes early Sentry init consent detection by updating hasMetricsConsent() to read persist:AnalyticsController from redux-persist-filesystem-storage (fallback to legacy METRICS_OPT_IN), and keeps the in-memory consent cache in sync via updateCachedConsent() from settings; tests were updated/added for these behaviors.

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

@github-actions

Copy link
Copy Markdown
Contributor

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.

@salimtb salimtb marked this pull request as ready for review April 30, 2026 08:06
@salimtb salimtb requested review from a team as code owners April 30, 2026 08:06
Comment thread app/util/trace.ts Outdated
Comment thread app/util/trace.ts Outdated
salimtb
salimtb previously approved these changes Apr 30, 2026
Comment thread app/components/UI/AssetOverview/Price/Price.advanced.tsx
Comment thread app/util/trace.ts Outdated
Comment thread app/util/trace.ts
Comment thread app/util/trace.ts Outdated
Comment thread app/components/UI/Charts/AdvancedChart/AdvancedChart.tsx Outdated
salimtb
salimtb previously approved these changes May 4, 2026

@salimtb salimtb 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.

LGTM

@github-actions github-actions Bot added size-L and removed size-M labels May 4, 2026
@sahar-fehri sahar-fehri changed the title chore: add advanced charts traces chore: add advanced charts traces cp-7.76.0 May 4, 2026
salimtb
salimtb previously approved these changes May 4, 2026

@NicolasMassart NicolasMassart 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.

found a small bug that may degrade data collection quality for impatient users (not waiting for the skeleton to disapear).
This is not critical but also not so hard to fix.

Comment thread app/components/UI/AssetOverview/Price/Price.advanced.tsx Outdated

@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.

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 eb2a3e0. Configure here.

Comment thread app/components/UI/AssetOverview/Price/Price.advanced.tsx
@github-actions

github-actions Bot commented May 5, 2026

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: None (no tests recommended)
  • Selected Performance tags: None (no tests recommended)
  • Risk Level: low
  • AI Confidence: 88%
click to see 🤖 AI reasoning details

E2E Test Selection:
The PR introduces performance tracing instrumentation for the advanced chart component and improves analytics consent cache management. Specifically:

  1. app/util/trace.ts: Adds new TraceName and TraceOperation enum values for token overview advanced chart tracing. Changes hasMetricsConsent() to read from FilesystemStorage (AnalyticsController persisted state) before falling back to legacy storage. Adds updateCachedConsent export. These are internal Sentry/performance monitoring changes that don't affect E2E-testable behavior.

  2. app/components/UI/Charts/AdvancedChart/AdvancedChart.tsx + .types.ts: Adds a new optional onSkeletonHidden callback prop that fires once when the chart skeleton overlay is removed. This is purely additive and doesn't change existing behavior.

  3. app/components/UI/AssetOverview/Price/Price.advanced.tsx: Integrates performance tracing using the new trace names to measure chart visibility timing. Uses useEffect and useRef hooks to track trace lifecycle. No UI behavior changes.

  4. app/components/Views/Settings/SecuritySettings/Sections/MetaMetricsAndDataCollectionSection/MetaMetricsAndDataCollectionSection.tsx: Calls updateCachedConsent() when user opts in/out of analytics to keep the in-memory cache in sync. The actual opt-in/opt-out behavior is unchanged.

  5. Test files: Unit tests for the above changes.

None of these changes affect core wallet functionality, transaction flows, account management, network management, or any other E2E-testable user flows. The changes are purely internal performance instrumentation and analytics consent cache improvements. No E2E test tags are warranted.

Performance Test Selection:
While the changes add Sentry performance tracing instrumentation to the advanced chart component, they don't change the actual rendering performance characteristics of the app. The changes are additive (new callbacks, new trace calls) and don't modify the rendering pipeline, data loading, or state management in ways that would affect measured performance metrics. No performance test tags are needed.

View GitHub Actions results

@sonarqubecloud

sonarqubecloud Bot commented May 5, 2026

Copy link
Copy Markdown

@NicolasMassart NicolasMassart 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 to me.

@sahar-fehri sahar-fehri enabled auto-merge May 6, 2026 10:26
@sahar-fehri sahar-fehri added this pull request to the merge queue May 6, 2026
Merged via the queue into main with commit b14edae May 6, 2026
60 checks passed
@sahar-fehri sahar-fehri deleted the chore/add-advanced-charts-traces branch May 6, 2026 13:36
@github-actions github-actions Bot locked and limited conversation to collaborators May 6, 2026
@metamaskbotv2 metamaskbotv2 Bot added the release-7.77.0 Issue or pull request that will be included in release 7.77.0 label May 6, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.77.0 Issue or pull request that will be included in release 7.77.0 size-L team-assets

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants