MetaMask / metamask-extension

:globe_with_meridians: :electric_plug: The MetaMask browser extension enables browsing Ethereum blockchain enabled websites
https://metamask.io
Other
12.07k stars 4.93k forks source link

perf: Configure `shouldCreateSpanForRequest` option for Sentry `browserTracingIntegration` #28613

Open MajorLift opened 4 days ago

MajorLift commented 4 days ago

Motivation

The Sentry browser tracing integration intercepts all outgoing fetch requests, and measures their duration in automatically-generated http.client spans.

Currently, our Sentry configuration does not exclude POST requests to Sentry DSN endpoints from this process. Unfortunately, these requests appear to have been taking up not just a non-negligible, but an outright dominating footprint in our Sentry performance quota and budget.

Based on usage data over the past 90 days in our metamask Sentry project, we can make the following observations (the following data only covers requests sent to sentry.io, and doesn't include requests sent to hostnames under that domain e.g. *.ingest.us.sentry.io):

Screenshot 2024-11-21 at 8 16 04 AM

https://metamask.sentry.io/performance/summary/spans/?project=273505&query=&statsPeriod=90d&transaction=%2Fpopup.html

Screenshot 2024-11-21 at 8 17 20 AM

https://metamask.sentry.io/performance/summary/spans/?project=273505&query=&statsPeriod=90d&transaction=%2Fhome.html

Screenshot 2024-11-21 at 8 18 37 AM

https://metamask.sentry.io/performance/summary/spans/http.client:8ee04019c21406cc/?project=273505&query=&sort=-span.duration&statsPeriod=90d&transaction=%2Fpopup.html

Screenshot 2024-11-21 at 8 18 43 AM

https://metamask.sentry.io/performance/summary/spans/http.client:8ee04019c21406cc/?project=273505&query=&sort=-span.duration&statsPeriod=90d&transaction=%2Fhome.html

Description

To fix this, we need to filter out communications with Sentry itself from the monitoring data that is logged to the Sentry dashboard.

This commit achieves this by configuring Sentry's browser tracing integration with its shouldCreateSpanForRequest option.

Open in GitHub Codespaces

Related issues

Manual testing steps

  1. Initialize the MetaMask extension with Sentry enabled.
  2. [Optional] Take actions that are measured by custom spans (e.g. toggle between account overview tabs, load the account list). This isn't necessary, as communications with Sentry will already have taken place in the first step.
  3. Verify in the Sentry dashboard that no recent http.client spans for 'sentry.io' have been logged.

Screenshots/Recordings

Before

Note the three http.client spans for 'sentry.io':

Screenshot 2024-11-21 at 8 37 55 AM

After

No auto-generated http.client spans show up in the Sentry dashboard for POST requests to the Sentry DSN endpoint, even though the requests are still going out.

http.client spans for other URLs are still being created and measured.

Screenshot 2024-11-21 at 7 49 39 AM

Pre-merge author checklist

Pre-merge reviewer checklist

github-actions[bot] commented 4 days ago

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.

metamaskbot commented 4 days ago
Builds ready [9142f93]
Page Load Metrics (1967 ± 79 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint17622305196616177
domContentLoaded17432293193315172
load17542309196716579
domInteractive178240178
backgroundConnect1189342713
firstReactRender783921467536
getState56017188
initialActions01000
loadScripts12611769143113866
setupStore68614199
uiStartup195027812234243117
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 59 Bytes (0.00%)
metamaskbot commented 3 days ago
Builds ready [0552f10]
Page Load Metrics (2053 ± 102 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint30327981780626301
domContentLoaded17662700202418991
load177228462053212102
domInteractive16217604321
backgroundConnect8112353215
firstReactRender981631232110
getState56119199
initialActions00000
loadScripts12952135150016981
setupStore65813157
uiStartup198031962298251121
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 88 Bytes (0.00%)