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

Add web3 usage metrics, prepare for web3 removal #9144

Merged
merged 3 commits into from
Aug 7, 2020

Conversation

rekmarks
Copy link
Member

@rekmarks rekmarks commented Aug 6, 2020

This PR adds window.web3 usage metrics for users that opted in to metrics. It also consolidates some web3-related functionality, and adds a method and a middleware to perform the metrics-sending work.

  • Add window.web3 usage metrics via new RPC method: metamask_logInjectedWeb3Usage
  • Send window.web3 usage metrics on window.web3 property access and assignment, via proxy handlers
  • Consolidate inpage web3-related code into auto-reload.js; rename file to setupWeb3.js
  • Create new, top-level RPC method middleware for the metamask_logInjectedWeb3Usage implementation
  • Create new, top-level metamask-controller method for sending backend metrics
    • For great DRYness
  • Rename permissions controller methodMiddleware.js to permissionsMethodMiddleware.js to distinguish from new top-level methodMiddleware

@rekmarks rekmarks changed the title Add web3 usage metrics Add web3 usage metrics, prepare for web3 removal Aug 6, 2020
@rekmarks rekmarks marked this pull request as ready for review August 6, 2020 20:36
@rekmarks rekmarks requested a review from a team as a code owner August 6, 2020 20:36
@rekmarks rekmarks requested a review from whymarrh August 6, 2020 20:36
@metamaskbot
Copy link
Collaborator

Builds ready [44298af]
Page Load Metrics (605 ± 18 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint28433542
domContentLoaded5577196033718
load5587206053718
domInteractive5577196033718

app/scripts/lib/backend-metametrics.js Outdated Show resolved Hide resolved
ui/app/helpers/utils/metametrics.util.js Outdated Show resolved Hide resolved
* move web3 metrics method to new middleware
@@ -4,7 +4,7 @@ import { ethErrors } from 'eth-json-rpc-errors'
/**
* Create middleware for handling certain methods and preprocessing permissions requests.
*/
export default function createMethodMiddleware ({
export default function createPermissionsMethodMiddleware ({
Copy link
Member Author

Choose a reason for hiding this comment

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

This file and all references to its export were renamed to disambiguate it from the new top-level methodMiddleware.

app/scripts/metamask-controller.js Outdated Show resolved Hide resolved
app/scripts/metamask-controller.js Outdated Show resolved Hide resolved
ui/app/helpers/utils/metametrics.util.js Outdated Show resolved Hide resolved
import 'web3/dist/web3.min.js'

const shouldLogUsage = !([
'docs.metamask.io',
Copy link
Member

Choose a reason for hiding this comment

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

Interesting - are these sites using web3?

Copy link
Member

Choose a reason for hiding this comment

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

Ah right, the test dapp definitely is. For the others, it might be useful to know if they're using the injected web3 instance though. That would be something we should fix.

Copy link
Member Author

Choose a reason for hiding this comment

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

I swear to verify this manually 😄

Copy link
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

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

LGTM! Though I did have one outstanding suggestion, of relatively low importance.

@rekmarks rekmarks merged commit e5cb63e into develop Aug 7, 2020
@rekmarks rekmarks deleted the web3-deprecation-metrics branch August 7, 2020 19:28
@metamaskbot
Copy link
Collaborator

Builds ready [70b50a0]
Page Load Metrics (677 ± 48 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint31105502210
domContentLoaded32582467610148
load32982667710048
domInteractive32582467510148

Gudahtt pushed a commit that referenced this pull request Aug 7, 2020
* add web3 usage metrics

* move web3 metrics method to new middleware

* rename some methods, files, and exports
@metamaskbot metamaskbot mentioned this pull request Aug 7, 2020
Gudahtt added a commit that referenced this pull request Aug 10, 2020
* origin/master: (44 commits)
  Add category in eventOpts (#9164)
  Update changelog for v8.0.7 (#9161)
  Version v8.0.7
  Remove web3 e2e tests (#9159)
  Add web3 usage metrics, prepare for web3 removal (#9144)
  Use `pathname` instead of URL for `currentPath` metrics parameter (#9158)
  Remove `url` parameter from `metricsEvent` (#9157)
  Change MetaMetrics category for background events (#9155)
  remove .network-name height
  Use luxon@1.24.1 (#9154)
  Update 'react-devtools' to ^4.8.0 (#9140)
  Fix connection removal bug (#9137)
  Add source map validator to CI (#9135)
  Update source map validator target files (#9133)
  Improve sourcemap validator console report (#9131)
  Add `validate-source-maps` npm script (#9134)
  Non-zero exit code upon failure to validate source maps (#9132)
  Update `brfs` from v1.6.1 to v2.0.2 (#9115)
  Factor out `getEnvironment` function in build script (#9114)
  Update `browserify` from v16.2.3 to v16.5.1 (#9113)
  ...
Gudahtt added a commit that referenced this pull request Aug 18, 2020
The web3 usage metrics added in #9144 assumed that all web3 properties
were strings. When a `Symbol` property is accessed, our `inpage.js`
script crashes because the `Symbol` cannot be serialized correctly.

A check has been added for non-string property access. The metric event
in these cases is set to the string "typeof ", followed by the type of
the key. (e.g. `typeof symbol` for a `Symbol` property).

Fixes #9234
Gudahtt added a commit that referenced this pull request Aug 18, 2020
The web3 usage metrics added in #9144 assumed that all web3 properties
were strings. When a `Symbol` property is accessed, our `inpage.js`
script crashes because the `Symbol` cannot be serialized correctly.

A check has been added for non-string property access. The metric event
in these cases is set to the string "typeof ", followed by the type of
the key. (e.g. `typeof symbol` for a `Symbol` property).

Fixes #9234
Gudahtt added a commit that referenced this pull request Aug 18, 2020
The web3 usage metrics added in #9144 assumed that all web3 properties
were strings. When a `Symbol` property is accessed, our `inpage.js`
script crashes because the `Symbol` cannot be serialized correctly.

A check has been added for non-string property access. The metric event
in these cases is set to the string "typeof ", followed by the type of
the key. (e.g. `typeof symbol` for a `Symbol` property).

Fixes #9234
Gudahtt added a commit that referenced this pull request Aug 19, 2020
The web3 usage metrics added in #9144 assumed that all web3 properties
were strings. When a `Symbol` property is accessed, our `inpage.js`
script crashes because the `Symbol` cannot be serialized correctly.

A check has been added for non-string property access. The metric event
in these cases is set to the string "typeof ", followed by the type of
the key. (e.g. `typeof symbol` for a `Symbol` property).

Fixes #9234
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants