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

feat: Add RPC Method Middleware params transform and tracking #23236

Conversation

jiexi
Copy link
Contributor

@jiexi jiexi commented Feb 28, 2024

Description

Currently we track a sample of most RPC method calls, but we do not include params. This is for good reason of course since many param values are sensitive and may identify an otherwise anonymous MetaMask Metrics user. There are some param values that are not sensitive yet are not tracked as well. Our goal is to glean additional insight into the usage of our RPC methods by including non-sensitive params in the events that track them.

This PR achieves that by including a map of method to transformation functions which accepts a request's params object (or array) and transforms it something that is acceptable for analytics. By default no params are included.

Open in GitHub Codespaces

Related issues

Fixes: https://github.com/MetaMask/MetaMask-planning/issues/2167

Manual testing steps

  1. Opt into MetaMetrics in the wallet settings
  2. Open your the background console for extension
  3. Add a breakpoint for trackEvent inside createRPCMethodTrackingMiddleware.js
  4. On any page with a provider injected, use window.ethereum.request to make some rpc method calls
  5. Check background console for breakpoint trigger

NOTE: I recommend breakpoint and debugger over the network tab because I don't believe the tracking requests actually fire on dev.

Screenshots/Recordings

Before

After

Pre-merge author checklist

  • I’ve followed MetaMask Coding Standards.
  • I've clearly explained what problem this PR is solving and how it is solved.
  • I've linked related issues
  • I've included manual testing steps
  • I've included screenshots/recordings if applicable
  • I’ve included tests if applicable
  • I’ve documented my code using JSDoc format if applicable
  • I’ve applied the right labels on the PR (see labeling guidelines). Not required for external contributors.
  • I’ve properly set the pull request status:
    • In case it's not yet "ready for review", I've set it to "draft".
    • In case it's "ready for review", I've changed it from "draft" to "non-draft".

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.

@jiexi jiexi self-assigned this Feb 28, 2024
@jiexi jiexi changed the title Add RPC Method Middleware params transform and tracking feat: Add RPC Method Middleware params transform and tracking Feb 28, 2024
@jiexi jiexi marked this pull request as ready for review February 29, 2024 18:05
@jiexi jiexi requested a review from a team as a code owner February 29, 2024 18:05
@metamaskbot
Copy link
Collaborator

Builds ready [5ca60dc]
Page Load Metrics (1417 ± 426 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint801971303517
domContentLoaded1393372010
load6623181417887426
domInteractive1393372010
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 97 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@metamaskbot
Copy link
Collaborator

Builds ready [26c03a1]
Page Load Metrics (587 ± 400 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint733911467837
domContentLoaded14167403316
load612173587834400
domInteractive14167403316
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 97 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@metamaskbot
Copy link
Collaborator

Builds ready [8722c2b]
Page Load Metrics (1199 ± 599 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint612011214019
domContentLoaded97028168
load56305211991247599
domInteractive97028168
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 97 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@metamaskbot
Copy link
Collaborator

Builds ready [20e5158]
Page Load Metrics (1252 ± 567 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint7838418110350
domContentLoaded17145423115
load65319312521180567
domInteractive17145423115
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 97 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

Copy link

codecov bot commented Mar 25, 2024

Codecov Report

Attention: Patch coverage is 70.00000% with 3 lines in your changes are missing coverage. Please review.

Project coverage is 67.42%. Comparing base (4135b68) to head (004e189).
Report is 5 commits behind head on develop.

Files Patch % Lines
...p/scripts/lib/createRPCMethodTrackingMiddleware.js 70.00% 3 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           develop   #23236   +/-   ##
========================================
  Coverage    67.42%   67.42%           
========================================
  Files         1295     1295           
  Lines        50378    50383    +5     
  Branches     13047    13049    +2     
========================================
+ Hits         33964    33969    +5     
  Misses       16414    16414           

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

@metamaskbot
Copy link
Collaborator

Builds ready [1dd2e46]
Page Load Metrics (1281 ± 580 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint631961113818
domContentLoaded98421199
load52285412811208580
domInteractive98421199
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 97 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@metamaskbot
Copy link
Collaborator

Builds ready [db630ed]
Page Load Metrics (520 ± 436 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint5913286199
domContentLoaded8271242
load472476520908436
domInteractive8271242
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 97 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

Copy link
Contributor

@adonesky1 adonesky1 left a comment

Choose a reason for hiding this comment

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

LGTM!

@metamaskbot
Copy link
Collaborator

Builds ready [004e189]
Page Load Metrics (1546 ± 581 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint671741103316
domContentLoaded9471794
load58304115461210581
domInteractive9471794
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 97 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@adonesky1 adonesky1 merged commit 7c36209 into develop May 22, 2024
72 checks passed
@adonesky1 adonesky1 deleted the jl/MMP-2167/analytics-tracking-rpc-method-params-transform-whitelist branch May 22, 2024 15:58
@github-actions github-actions bot locked and limited conversation to collaborators May 22, 2024
@gauthierpetetin gauthierpetetin added the release-12.0.0 Issue or pull request that will be included in release 12.0.0 label Jun 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
release-12.0.0 Issue or pull request that will be included in release 12.0.0 team-data-and-analytics team-wallet-api-platform
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

6 participants