-
Notifications
You must be signed in to change notification settings - Fork 5k
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
Set sentry autoTrackSessions default #20132
Conversation
ui/store/actions.test.js
Outdated
describe('#setParticipateInMetaMetrics', () => { | ||
beforeAll(() => { | ||
window.sentry = { | ||
toggleSession: jest.fn(), | ||
endSession: jest.fn(), | ||
}; | ||
}); | ||
it('sets participateInMetaMetrics to true', async () => { | ||
const store = mockStore(); | ||
const setParticipateInMetaMetricsStub = sinon | ||
.stub() | ||
.callsFake((_, cb) => cb()); | ||
|
||
background.getApi.returns({ | ||
setParticipateInMetaMetrics: setParticipateInMetaMetricsStub, | ||
}); | ||
|
||
_setBackgroundConnection(background.getApi()); | ||
|
||
await store.dispatch(actions.setParticipateInMetaMetrics(true)); | ||
expect(setParticipateInMetaMetricsStub.calledOnceWith(true)).toBeTruthy(); | ||
expect(window.sentry.toggleSession).toHaveBeenCalled(); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No tests existed for setParticipateInMetaMetrics before. So this minimal test case covers the newly added code plus the happy path of enabling the flag.
Codecov Report
@@ Coverage Diff @@
## develop #20132 +/- ##
===========================================
- Coverage 69.48% 69.45% -0.03%
===========================================
Files 984 984
Lines 37328 37355 +27
Branches 10035 10049 +14
===========================================
+ Hits 25935 25943 +8
- Misses 11393 11412 +19
|
Builds ready [949f93a]
Page Load Metrics (1563 ± 52 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
app/scripts/lib/setupSentry.js
Outdated
* change may result in the FilterEvents integration no longer being | ||
* necessary, but that should be tested and executed in a future PR. | ||
* | ||
* TODO: Potentially remove the FilterEvents integration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit] If this TODO
is outside of this task, can you please create a task for it and link it in this comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, Pedro!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#20174 -- ill update the comment in a bit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See here: #15677
The FilterEvents
integration is used over beforeSend
to workaround the incompatibility between beforeSend
and Dedupe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I'll close the issue and remove the change to beforeSend then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes to beforeSend were reverted and the comment removed @pedronfigueiredo and @Gudahtt
Builds ready [a16a65d]
Page Load Metrics (1558 ± 39 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
a16a65d
to
9dff5a3
Compare
Builds ready [9dff5a3]
Page Load Metrics (1664 ± 51 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
@@ -146,6 +146,14 @@ describe('MetaMetricsController', function () { | |||
const now = new Date(); | |||
let clock; | |||
beforeEach(function () { | |||
globalThis.sentry = { | |||
startSession: sinon.fake(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use jest.fn()
here to mock?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not without rewriting the tests to jest. Currently in mocha
await driver.fill('#password', 'correct horse battery staple'); | ||
await driver.press('#password', driver.Key.ENTER); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
await driver.fill('#password', 'correct horse battery staple'); | |
await driver.press('#password', driver.Key.ENTER); | |
await unlockWallet(driver) |
await driver.press('#password', driver.Key.ENTER); | ||
// Trigger error | ||
driver.executeScript('window.stateHooks.throwTestError()'); | ||
driver.delay(3000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: is there a way to bypass the delay here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No we need to wait sometime to give time for a network request to occur
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the inverse test, we wait for a specific network request. I want to give a similar pause but we can't wait for anything in particular.
ui/store/actions.test.js
Outdated
const setParticipateInMetaMetricsStub = sinon | ||
.stub() | ||
.callsFake((_, cb) => cb()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we use jest here as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Id rather do that as a larger part of fixing the actions test file to remove sinon. I copied patterns used for other background methods here. Do we have an issue to track dropping sinon?
Changed my mind after thinking about it. We do need to try and commit to making incremental changes when we do not have the time to do the more extreme work required. This was the right call here and it also helps to set an example for future extensions of a file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mmm... i might retract my statement. let me give it a stab and see how it looks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added the jest version and removed the additional sinon usage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Builds ready [78b278f]
Page Load Metrics (1596 ± 53 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
LGTM |
Explanation
AutoSessionTracking defaults to true and operates by sending a session packet to sentry. This session packet does not appear to be filtered out via our beforeSend or FilterEvents integration. To avoid sending a request before we have the state tree and can validate the users preferences, we initiate this to false. Later, in startSession and endSession we modify this option and start the session or end the session manually. We also provide a toggleSession method that uses current state to determine whether to start or stop the session.
In sentry-install we call toggleSession after the page loads and state is available, this handles initiating the session for a user who has opted into MetaMetrics. This script is ran in both the background and UI so it should be effective at starting the session in both places.
In the MetaMetricsController the session is manually started or stopped when the user opts in or out of MetaMetrics. This occurs in the setParticipateInMetaMetrics function which is exposed to the UI via the MetaMaskController.
In actions.ts, after successfully calling the setParticipateInMetaMetrics background method, we tell sentry to toggle the session details appropriately.
Types for the global Sentry object, and the new methods added as part of this effort were added to global.d.ts in the types folder.
Another minor change is changing the throwTestError method so that it takes an optional input for the message text so that the Dedupe filter of sentry doesn't catch it for testing purposes. Without debug enabled in the sentry options you are unaware that the message is being dropped by that handler.
Added an INVERSE test case, asserting that requests are NOT sent to sentry when the flag is false.
Screenshots/Screencaps
Before
before.mov
After
after.mov
Manual Testing Steps With Existing Wallet
yarn build dist
-- dev mode does not have a sentry global object attached to it. If you want to use dev mode, you need to comment out the 'return undefined' line in setupSentry with the comment block that talks about the bug with sentry in dev mode.The next steps only work on this branch:
window.stateHooks.throwTestError()
window.stateHooks.throwTestError('foo')
Test requests sent during onboarding
yarn build:test
(easier to get to a clean wallet)Pre-merge author checklist
Pre-merge reviewer checklist
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.