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

Fix Sentry breadcrumbs collection during initialization #20521

Merged
merged 6 commits into from
Aug 18, 2023

Conversation

Gudahtt
Copy link
Member

@Gudahtt Gudahtt commented Aug 17, 2023

Explanation

The refactor of the Sentry state in #20491 accidentally broke our opt- in detection in the beforeBreadcrumbs hook for errors in the background process. It would have broken our error report opt-in detection as well, except that that function was broken in a way that made it work correctly but inefficiently (it was loading the persisted state each time to check, ignoring the application state).

The opt-in detection has been updated to look for both types of application state (during and after initialization). The function was refactored to be used for the beforeBreadcrumbs hook as well.

Manual Testing Steps

This was discovered by @danjm when investigating the e2e test failure in #20517. This can be tested by following a similar approach to the failing e2e test: modify the persisted state in a way that breaks a migration, and ensure the breadcrumbs are collected.

The steps I took are:

chrome.storage.local.get(({ data, meta }) => chrome.storage.local.set({ data: { ...data, MetaMetricsController: { ...data.MetaMetricsController, participateInMetaMetrics: true }, OnboardingController: { ...data.OnboardingController, completedOnboarding: true }, NftController: false }, meta: {...meta, version: 20} }, () => { window.location.reload() }))
  • This snippet sets the version back far enough that there are plenty of console logs/breadcrumbs to collect
  • onboardingComplete is set to true and participateInMetaMetrics is set to true so that the request goes through and breadcrumbs aren't suppressed
  • See that there is a resulting Sentry error report in the network tab, and breadcrumbs are included in the payload
  • Try again with onboardingComplete set to false, and you should see the same error report but without the breadcrumbs
  • Try again with participateInMetaMetrics set to false and there should be no error report
  • After initialization, try running window.stateHooks.throwTestError() in the UI (checking the network tab to see whether an error is sent, and whether it has breadcrumbs, which should depend on the two properties referenced earlier)
  • After initialization, try running window.stateHooks.throwTestBackgroundError() in the UI (checking the network tab to see whether an error is sent, and whether it has breadcrumbs, which should depend on the two properties referenced earlier)

Pre-merge author checklist

  • I've clearly explained:
    • What problem this PR is solving
    • How this problem was solved
    • How reviewers can test my changes
  • Sufficient automated test coverage has been added

Pre-merge reviewer checklist

  • Manual testing (e.g. pull and build branch, run in browser, test code being changed)
  • PR is linked to the appropriate GitHub issue
  • IF this PR fixes a bug in the release milestone, add this PR to the release milestone

If further QA is required (e.g. new feature, complex testing steps, large refactor), add the Extension QA Board label.

In this case, a QA Engineer approval will be be required.

The refactor of the Sentry state in #20491 accidentally broke our opt-
in detection. The opt-in detection has been updated to look for both
types of application state (during and after initialization).
@Gudahtt Gudahtt force-pushed the fix-sentry-enabled-detection branch from 6ebbff1 to 0ee1b5f Compare August 17, 2023 23:46
The check for whether the user had completed onboarding assumed that
the application state was post-initialization UI state. It has been
updated to handle background state and pre-initialization state as
well.
@metamaskbot
Copy link
Collaborator

Builds ready [0ee1b5f]
Page Load Metrics (1596 ± 42 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint1092181352512
domContentLoaded1414174115968742
load1414174115968742
domInteractive1414174115958742
Bundle size diffs [🚀 Bundle size reduced!]
  • background: -55 Bytes (-0.00%)
  • ui: 0 Bytes (0.00%)
  • common: -55 Bytes (-0.00%)

@Gudahtt
Copy link
Member Author

Gudahtt commented Aug 18, 2023

OK, test instructions updated, I think it works now. I was thrown off at first because I wasn't seeing any breadcrumbs, but that was because I was only moving the state back to migration 91, which is far enough to produce console warnings but not far enough to guarantee they're picked up by Sentry in time to be included.

@Gudahtt Gudahtt marked this pull request as ready for review August 18, 2023 01:01
@Gudahtt Gudahtt requested a review from a team as a code owner August 18, 2023 01:01
@codecov
Copy link

codecov bot commented Aug 18, 2023

Codecov Report

Merging #20521 (a745509) into develop (88212a7) will decrease coverage by 0.03%.
The diff coverage is 0.00%.

@@             Coverage Diff             @@
##           develop   #20521      +/-   ##
===========================================
- Coverage    68.68%   68.65%   -0.03%     
===========================================
  Files          991      991              
  Lines        38451    38467      +16     
  Branches     10329    10333       +4     
===========================================
  Hits         26409    26409              
- Misses       12042    12058      +16     
Files Changed Coverage Δ
app/scripts/lib/setupSentry.js 41.07% <0.00%> (-4.32%) ⬇️

danjm
danjm previously approved these changes Aug 18, 2023
Copy link
Contributor

@danjm danjm 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 [aabb66b]
Page Load Metrics (1551 ± 55 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint107172119136
domContentLoaded13961913155111555
load13971914155111555
domInteractive13961913155111555
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 295 Bytes (0.01%)
  • ui: 0 Bytes (0.00%)
  • common: 295 Bytes (0.01%)

@Gudahtt Gudahtt added the release-blocker This bug is blocking the next release label Aug 18, 2023
app/scripts/lib/setupSentry.js Outdated Show resolved Hide resolved
app/scripts/lib/setupSentry.js Outdated Show resolved Hide resolved
app/scripts/lib/setupSentry.js Outdated Show resolved Hide resolved
app/scripts/lib/setupSentry.js Outdated Show resolved Hide resolved
@Gudahtt Gudahtt requested a review from danjm August 18, 2023 02:07
@metamaskbot
Copy link
Collaborator

Builds ready [a745509]
Page Load Metrics (1914 ± 73 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint1162321622914
domContentLoaded15772161191115173
load15772187191415373
domInteractive15772161191115173
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 255 Bytes (0.01%)
  • ui: 0 Bytes (0.00%)
  • common: 255 Bytes (0.01%)

Copy link
Contributor

@danjm danjm left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@NidhiKJha NidhiKJha left a comment

Choose a reason for hiding this comment

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

LGTM! PR description is written very nicely 🤩

@danjm danjm merged commit 65c13d3 into develop Aug 18, 2023
@danjm danjm deleted the fix-sentry-enabled-detection branch August 18, 2023 08:17
@github-actions github-actions bot locked and limited conversation to collaborators Aug 18, 2023
@metamaskbot metamaskbot added the release-10.36.0 Issue or pull request that will be included in release 10.36.0 label Aug 18, 2023
@Gudahtt Gudahtt removed the release-10.36.0 Issue or pull request that will be included in release 10.36.0 label Sep 19, 2023
@Gudahtt Gudahtt added the release-10.34.5 Issue or pull request that will be included in release 10.34.5 label Sep 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
release-10.34.5 Issue or pull request that will be included in release 10.34.5 release-blocker This bug is blocking the next release team-extension-platform
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants