feat: emit RPC service analytics from NetworkController (core)#43934
feat: emit RPC service analytics from NetworkController (core)#43934cryptodev-2s wants to merge 4 commits into
Conversation
NetworkController now emits the "RPC Service Unavailable" and "RPC Service Degraded" analytics events itself (via the new core analytics option that calls AnalyticsController:trackEvent), so the extension no longer needs to subscribe to the rpcEndpointUnavailable/rpcEndpointDegraded events and translate them by hand. Changes: - Pass the new `analytics` option to NetworkController with the extension's isPublicEndpointUrl predicate and a sample rate derived from the build environment. - Delegate AnalyticsController:getState and AnalyticsController:trackEvent to the NetworkController messenger so the controller can deliver events. - Delete the duplicated messenger-action-handlers, drop the now unused NetworkController init messenger, and slim utils down to the sample rate helper. Uses a preview build of @metamask/network-controller while the core PR is in review.
|
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. |
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
|
@metamaskbot update-policies |
|
Policies updated. Tip Follow the policy review process outlined in the LavaMoat Policy Review Process doc before expecting an approval from Policy Reviewers. 👀 lavamoat/browserify/beta/policy.json changes differ from lavamoat/browserify/main/policy.json changes |
✨ Files requiring CODEOWNER review ✨📜 @MetaMask/policy-reviewers (12 files, +48 -0)
Tip Follow the policy review process outlined in the LavaMoat Policy Review Process doc before expecting an approval from Policy Reviewers. |
Builds ready [dccd401]
⚡ Performance Benchmarks (Total: 🟢 19 pass · 🟡 4 warn · 🔴 1 fail)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
|
Builds ready [4827d78]
⚡ Performance Benchmarks (Total: 🟢 19 pass · 🟡 5 warn · 🔴 0 fail)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|



Description
Draft to verify the new
@metamask/network-controlleranalytics logic (MetaMask/core#9270) works end to end in the extension.Previously the extension subscribed to NetworkController's
rpcEndpointUnavailable/rpcEndpointDegradedevents and translated them into theRPC Service Unavailable/RPC Service DegradedSegment events by hand, duplicating logic that mobile also carries. The core change moves that translation into NetworkController itself, which now emits the events throughAnalyticsController:trackEvent.This PR wires the extension onto that new logic:
network-controller-init.ts: pass the newanalyticsoption toNetworkController:isRpcEndpointUrlPublic: the extension's existingisPublicEndpointUrl(url, infuraProjectId)rpcServiceEventsSampleRate: derived from the build environment (1% in production/RC, 100% in dev/test, 0 when unknown). The per user 1% sampling is now applied inside the controller.messengers/network-controller-messenger.ts: delegateAnalyticsController:getStateandAnalyticsController:trackEventto the NetworkController messenger so the controller can deliver events.rpcEndpointUnavailable/rpcEndpointDegradedsubscriptions,messenger-action-handlers.ts, and the now unused NetworkController init messenger.utils.tsslimmed to a singlegetRpcServiceEventsSampleRate()helper.Behavior parity is preserved (same events, names, properties, sampling, connection error skipping, public/private URL handling). The only move is that the logic lives in core now and delivers through
AnalyticsControllerinstead ofMetaMetricsController(mobile already routes through AnalyticsController). Uses a preview build of@metamask/network-controller(33.0.0-preview-14cbc2873) while the core PR is in review.Do not merge before MetaMask/core#9270 lands and a real
@metamask/network-controllerrelease replaces the preview resolution inpackage.json.Open question carried from core:
AnalyticsTrackingEventhas nocategoryfield, so the oldcategory: 'Network'is not carried right now, pending confirmation from the analytics owners.Changelog
CHANGELOG entry: null
Related issues
Fixes:
Manual testing steps
@metamask/network-controllerto the preview build).rpcEndpointUnavailable/rpcEndpointDegraded.RPC Service Unavailable/RPC Service Degradedevent is sent through AnalyticsController with the expected properties (chain_id_caip,rpc_domain, etc.).rpc_domain: customand that local connection errors do not produce events.Screenshots/Recordings
N/A (no UI changes)
Before
After
Pre-merge author checklist
Pre-merge reviewer checklist