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

refactor: Send signature metrics as event fragments in middleware & feat: Add signature alert metrics to events #26597

Merged
merged 15 commits into from
Sep 12, 2024

Conversation

digiwand
Copy link
Contributor

@digiwand digiwand commented Aug 21, 2024

Description

  • If the RPC request is a signature, send the event using event fragments so that we can add additional props before sending the final event
    • Pass MetaMetricsController to createRPCMethodTrackingMiddleware
  • Add signature alert metrics to events

Open in GitHub Codespaces

Related issues

Fixes: https://github.com/MetaMask/MetaMask-planning/issues/2718
Blocked by: https://github.com/MetaMask/core/pull/4636/files and following PRs to update packages

Manual testing steps

  1. Turn on metametrics through MM settings
  2. Go to test-dapp
  3. Trigger signature with alerts (e.g. Sign-in with Ethereum (Bad Domain))
  4. Observe new alert metrics in Segment/Mixpanel Signature Rejected/Approved events

Screenshots/Recordings

Before

After

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.

Copy link
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.

@digiwand digiwand force-pushed the feat-permit-alert-metrics branch from 8d7328d to cd0208f Compare August 27, 2024 15:04
digiwand added a commit to MetaMask/core that referenced this pull request Sep 3, 2024
…4636)

## Explanation

<!--
Thanks for your contribution! Take a moment to answer these questions so
that reviewers have the information they need to properly understand
your changes:

* What is the current state of things and why does it need to change?
* What is the solution your changes offer and how does it work?
* Are there any changes whose purpose might not obvious to those
unfamiliar with the domain?
* If your primary goal was to update one package but you found you had
to update another one along the way, why did you do so?
* If you had to upgrade a dependency, why did you do so?
-->

Adding the request id to reference metric event fragments created from
the createRPCMethodTrackingMiddleware in the client. See use-case here:
MetaMask/metamask-extension#26597

## References

<!--
Are there any issues that this pull request is tied to? Are there other
links that reviewers should consult to understand these changes better?

For example:

Blocks: MetaMask/metamask-extension#26597
* Fixes #12345
* Related to #67890
-->

## Changelog

<!--
If you're making any consumer-facing changes, list those changes here as
if you were updating a changelog, using the template below as a guide.

(CATEGORY is one of BREAKING, ADDED, CHANGED, DEPRECATED, REMOVED, or
FIXED. For security-related issues, follow the Security Advisory
process.)

Please take care to name the exact pieces of the API you've added or
changed (e.g. types, interfaces, functions, or methods).

If there are any breaking changes, make sure to offer a solution for
consumers to follow once they upgrade to the changes.

Finally, if you're only making changes to development scripts or tests,
you may replace the template below with "None".
-->

### `@metamask/message-manager`

- **feat**: Add request id to messageParams

## Checklist

- [ ] I've updated the test suite for new or updated code as appropriate
- [ ] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [ ] I've highlighted breaking changes using the "BREAKING" category
above as appropriate

---------

Co-authored-by: Jongsun Suh <jongsun.suh@icloud.com>
Copy link

codecov bot commented Sep 9, 2024

Codecov Report

Attention: Patch coverage is 65.21739% with 8 lines in your changes missing coverage. Please review.

Project coverage is 70.14%. Comparing base (416d024) to head (8cb7817).
Report is 7 commits behind head on develop.

Files with missing lines Patch % Lines
...p/scripts/lib/createRPCMethodTrackingMiddleware.js 64.29% 5 Missing ⚠️
...confirmations/hooks/useConfirmationAlertMetrics.ts 57.14% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #26597      +/-   ##
===========================================
- Coverage    70.17%   70.14%   -0.03%     
===========================================
  Files         1425     1425              
  Lines        49659    49684      +25     
  Branches     13891    13898       +7     
===========================================
+ Hits         34846    34850       +4     
- Misses       14813    14834      +21     

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

@digiwand digiwand marked this pull request as ready for review September 9, 2024 10:33
@digiwand digiwand requested review from a team as code owners September 9, 2024 10:33
@metamaskbot
Copy link
Collaborator

Builds ready [ad65b1c]
Page Load Metrics (1896 ± 153 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint21328311571674324
domContentLoaded156125931877305147
load156927201896318153
domInteractive17127422814
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 305 Bytes (0.01%)
  • ui: 217 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@digiwand digiwand changed the title refactor: send sign metrics as event fragments in middleware refactor: Send signature metrics as event fragments in middleware & feat: Add signature alert metrics to events Sep 9, 2024
jpuri
jpuri previously approved these changes Sep 9, 2024
@metamaskbot
Copy link
Collaborator

Builds ready [123fd08]
Page Load Metrics (1587 ± 67 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint22520061396504242
domContentLoaded13861854156411857
load13932022158713967
domInteractive12142332814
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 305 Bytes (0.01%)
  • ui: 217 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

const requestId = (currentConfirmation as SignatureRequestType)?.msgParams
?.requestId;
const fragmentUniqueId = `signature-${requestId}`;
updateEventFragment(fragmentUniqueId, {
Copy link
Member

Choose a reason for hiding this comment

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

Is it worth a parallel useSignatureEventFragment hook to encapsulate the generation of the fragment ID and allow other parts of the UI to add properties to signatures?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hey @matthewwalsh0! I think this is a good idea. We don't have additional use-cases for this yet, but I imagine we will. I have some code written now, but I think it should go in a separate PR. Will create one following the merge of this one

Copy link
Contributor Author

Choose a reason for hiding this comment

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

created here: #27043

Copy link
Contributor

Choose a reason for hiding this comment

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

or something similar to updateTransactionEventFragment to encapsulate this whole thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updateTransactionEventFragment is included in useSignatureEventFragment in #27043

I added a brief description of my thoughts using a hook vs. util function in the PR description. Curious if you two have additional opinions on this

heads up, PR is in draft as I'm working on supporting tests. I don't see unit tests for updateTransactionEventFragment so I think it relies on other tests to support the hook. Will take more time to investigate later

properties,
});
if (signatureUniqueId) {
metaMetricsController.updateEventFragment(signatureUniqueId, {
Copy link
Member

Choose a reason for hiding this comment

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

❤️

Copy link

sonarcloud bot commented Sep 9, 2024

@metamaskbot
Copy link
Collaborator

Builds ready [8cb7817]
Page Load Metrics (1733 ± 52 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint32720381678330158
domContentLoaded1554195317059746
load15952049173310852
domInteractive17159463115
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 307 Bytes (0.01%)
  • ui: 354 Bytes (0.00%)
  • common: 64 Bytes (0.00%)

finalizeSignatureFragment(metaMetricsController, req, {
abandoned: event === eventType.REJECTED,
properties,
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Hey @digiwand is event of type REJECTED received in this middleware ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hi @jpuri, yep! Within this next() node.js callback, the event is set based on the response above. This may include eventType.REJECTED

@digiwand digiwand requested a review from jpuri September 11, 2024 12:14
@digiwand digiwand merged commit 5622c34 into develop Sep 12, 2024
78 checks passed
@digiwand digiwand deleted the feat-permit-alert-metrics branch September 12, 2024 07:13
@github-actions github-actions bot locked and limited conversation to collaborators Sep 12, 2024
@metamaskbot metamaskbot added the release-12.6.0 Issue or pull request that will be included in release 12.6.0 label Sep 12, 2024
@metamaskbot metamaskbot added release-12.5.0 Issue or pull request that will be included in release 12.5.0 and removed release-12.6.0 Issue or pull request that will be included in release 12.6.0 labels Sep 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
release-12.5.0 Issue or pull request that will be included in release 12.5.0 team-confirmations Push issues to confirmations team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants