Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: add trace for UI startup (#26636) [cherry-pick] #26925

Merged
merged 5 commits into from
Sep 6, 2024

Conversation

Gudahtt
Copy link
Member

@Gudahtt Gudahtt commented Sep 4, 2024

This is a cherry-pick of #26332 and #26636 for v12.2.0, with the TransactionController update removed from #26332.

Follow these steps to manually test:

  • Create a personal Sentry account (if you don't have one already) and create a metamask project
  • Set the DSN of this project as SENTRY_DSN_DEV in your .metamaskrc file
  • Create a new dev build
  • Install the build and go through onboarding, ensuring that you opt-in to metrics
  • Make a few page navigations

You should see the UI traces in the Sentry performance dashboard on your personal account.

This was cherry-picked to get the benefits described in #26636 (#26332 was partially included only out of necessity). The original description of #26636 is below:

Description

Record a UI Startup Sentry trace to monitor startup times of the UI pages.

In addition:

  • Support use of trace utility function in non-asynchronous contexts.
    • Remove getMetaMetricsEnabled check as this is already done in the custom transport before submission.
  • Generate default ID if omitted when starting and ending traces.

Open in GitHub Codespaces

Related issues

Fixes: #25724

Manual testing steps

Screenshots/Recordings

Before

After

Sentry Console

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.

@Gudahtt Gudahtt force-pushed the cherry-pick/add-trace-for-ui-startup branch from 6654704 to baa689c Compare September 5, 2024 18:09
@Gudahtt Gudahtt marked this pull request as ready for review September 5, 2024 18:48
@Gudahtt Gudahtt requested review from a team as code owners September 5, 2024 18:48
@metamaskbot
Copy link
Collaborator

Builds ready [e1e4021]
Page Load Metrics (1681 ± 56 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint23021111549446214
domContentLoaded15112093165512057
load15242112168111756
domInteractive129333199

Copy link

codecov bot commented Sep 5, 2024

Codecov Report

Attention: Patch coverage is 61.81818% with 42 lines in your changes missing coverage. Please review.

Project coverage is 70.49%. Comparing base (a60dbcb) to head (19daa9f).

Files with missing lines Patch % Lines
ui/index.js 0.00% 23 Missing ⚠️
app/scripts/ui.js 0.00% 10 Missing ⚠️
shared/lib/trace.ts 89.47% 8 Missing ⚠️
app/scripts/lib/setupSentry.js 0.00% 1 Missing ⚠️
Additional details and impacted files
@@                 Coverage Diff                 @@
##           Version-v12.2.0   #26925      +/-   ##
===================================================
- Coverage            70.49%   70.49%   -0.00%     
===================================================
  Files                 1400     1400              
  Lines                49611    49687      +76     
  Branches             13647    13655       +8     
===================================================
+ Hits                 34971    35024      +53     
- Misses               14640    14663      +23     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

app/scripts/lib/createTracingMiddleware.ts Outdated Show resolved Hide resolved
app/scripts/lib/ppom/ppom-middleware.ts Outdated Show resolved Hide resolved
app/scripts/lib/transaction/util.ts Outdated Show resolved Hide resolved
app/scripts/metamask-controller.js Outdated Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't impact the build as it's developer only, though it applies the new TraceName enum.

Copy link
Member Author

Choose a reason for hiding this comment

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

Easier to leave this change in I think, to avoid a type error. The trace utility requires the enum to be used. We could adjust it to remove that requirement, but doesn't seem useful to do so

ui/store/actions.ts Outdated Show resolved Hide resolved
ui/store/actions.ts Outdated Show resolved Hide resolved
@danjm
Copy link
Contributor

danjm commented Sep 6, 2024

I have tested this and it works as expected. (But I did not test transactions, as per Matthew's comments above)

matthewwalsh0 and others added 5 commits September 6, 2024 10:02
Refactor `trace` utility function to support no callback argument and only start a trace to be manually ended later.
Add `endTrace` utility function.
Add `endBackgroundTrace` action to contribute to background metrics from the UI.
Always trace if in developer build or `METAMASK_DEBUG` is set.
Pass `trace` callback and `traceContext` to `TransactionController`.
Support use of `trace` utility function in non-asynchronous contexts.
Remove `getMetaMetricsEnabled` check.
Generate default ID if omitted when starting and ending traces.
@Gudahtt Gudahtt force-pushed the cherry-pick/add-trace-for-ui-startup branch from 1d34547 to 19daa9f Compare September 6, 2024 12:32
@Gudahtt
Copy link
Member Author

Gudahtt commented Sep 6, 2024

I have re-tested this locally with the unnecessary code removed, and it seems to work correctly still

@danjm
Copy link
Contributor

danjm commented Sep 6, 2024

Just retested as well. LGTM

@metamaskbot
Copy link
Collaborator

Builds ready [19daa9f]
Page Load Metrics (1742 ± 103 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint24523341681391188
domContentLoaded14622289172720598
load147023021742214103
domInteractive139033199

@Gudahtt Gudahtt merged commit 7cc4af7 into Version-v12.2.0 Sep 6, 2024
64 checks passed
@Gudahtt Gudahtt deleted the cherry-pick/add-trace-for-ui-startup branch September 6, 2024 16:24
@github-actions github-actions bot locked and limited conversation to collaborators Sep 6, 2024
@metamaskbot metamaskbot added the release-12.2.0 Issue or pull request that will be included in release 12.2.0 label Sep 6, 2024
@metamaskbot
Copy link
Collaborator

No release label on PR. Adding release label release-12.2.0 on PR, as PR was cherry-picked in branch 12.2.0.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
release-12.2.0 Issue or pull request that will be included in release 12.2.0 team-wallet-framework
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants