-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(browser): Ignore unrealistically long INP values #16484
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b56eea4
fix(browser): Ignore unrealistically long INP values
Lms24 0156209
add tests
Lms24 1cc4a8a
tests
Lms24 2993326
fix build error
Lms24 d37b462
size limit
Lms24 565f54d
improve tests
Lms24 5138f33
lint
Lms24 70ee6d5
add comment
Lms24 b888d02
.
Lms24 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
packages/browser-utils/test/instrument/metrics/inpt.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import { afterEach } from 'node:test'; | ||
import { describe, expect, it, vi } from 'vitest'; | ||
import { _onInp, _trackINP } from '../../../src/metrics/inp'; | ||
import * as instrument from '../../../src/metrics/instrument'; | ||
import * as utils from '../../../src/metrics/utils'; | ||
|
||
describe('_trackINP', () => { | ||
const addInpInstrumentationHandler = vi.spyOn(instrument, 'addInpInstrumentationHandler'); | ||
|
||
afterEach(() => { | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
it('adds an instrumentation handler', () => { | ||
_trackINP(); | ||
expect(addInpInstrumentationHandler).toHaveBeenCalledOnce(); | ||
}); | ||
|
||
it('returns an unsubscribe dunction', () => { | ||
const handler = _trackINP(); | ||
expect(typeof handler).toBe('function'); | ||
}); | ||
}); | ||
|
||
describe('_onInp', () => { | ||
it('early-returns if the INP metric entry has no value', () => { | ||
const startStandaloneWebVitalSpanSpy = vi.spyOn(utils, 'startStandaloneWebVitalSpan'); | ||
|
||
const metric = { | ||
value: undefined, | ||
entries: [], | ||
}; | ||
// @ts-expect-error - incomplete metric object | ||
_onInp({ metric }); | ||
|
||
expect(startStandaloneWebVitalSpanSpy).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('early-returns if the INP metric value is greater than 60 seconds', () => { | ||
const startStandaloneWebVitalSpanSpy = vi.spyOn(utils, 'startStandaloneWebVitalSpan'); | ||
|
||
const metric = { | ||
value: 60_001, | ||
entries: [ | ||
{ name: 'click', duration: 60_001, interactionId: 1 }, | ||
{ name: 'click', duration: 60_000, interactionId: 2 }, | ||
], | ||
}; | ||
// @ts-expect-error - incomplete metric object | ||
_onInp({ metric }); | ||
|
||
expect(startStandaloneWebVitalSpanSpy).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('early-returns if the inp metric has an unknown interaction type', () => { | ||
const startStandaloneWebVitalSpanSpy = vi.spyOn(utils, 'startStandaloneWebVitalSpan'); | ||
|
||
const metric = { | ||
value: 10, | ||
entries: [{ name: 'unknown', duration: 10, interactionId: 1 }], | ||
}; | ||
// @ts-expect-error - incomplete metric object | ||
_onInp({ metric }); | ||
|
||
expect(startStandaloneWebVitalSpanSpy).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('starts a span for a valid INP metric entry', () => { | ||
const startStandaloneWebVitalSpanSpy = vi.spyOn(utils, 'startStandaloneWebVitalSpan'); | ||
|
||
const metric = { | ||
value: 10, | ||
entries: [{ name: 'click', duration: 10, interactionId: 1 }], | ||
}; | ||
// @ts-expect-error - incomplete metric object | ||
_onInp({ metric }); | ||
|
||
expect(startStandaloneWebVitalSpanSpy).toHaveBeenCalledTimes(1); | ||
expect(startStandaloneWebVitalSpanSpy).toHaveBeenCalledWith({ | ||
attributes: { | ||
'sentry.exclusive_time': 10, | ||
'sentry.op': 'ui.interaction.click', | ||
'sentry.origin': 'auto.http.browser.inp', | ||
}, | ||
name: '<unknown>', | ||
startTime: NaN, | ||
transaction: undefined, | ||
}); | ||
}); | ||
|
||
it('takes the correct entry based on the metric value', () => { | ||
const startStandaloneWebVitalSpanSpy = vi.spyOn(utils, 'startStandaloneWebVitalSpan'); | ||
|
||
const metric = { | ||
value: 10, | ||
entries: [ | ||
{ name: 'click', duration: 10, interactionId: 1 }, | ||
{ name: 'click', duration: 9, interactionId: 2 }, | ||
], | ||
}; | ||
// @ts-expect-error - incomplete metric object | ||
_onInp({ metric }); | ||
|
||
expect(startStandaloneWebVitalSpanSpy).toHaveBeenCalledTimes(1); | ||
expect(startStandaloneWebVitalSpanSpy).toHaveBeenCalledWith({ | ||
attributes: { | ||
'sentry.exclusive_time': 10, | ||
'sentry.op': 'ui.interaction.click', | ||
'sentry.origin': 'auto.http.browser.inp', | ||
}, | ||
name: '<unknown>', | ||
startTime: NaN, | ||
transaction: undefined, | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
😂
I hope the git blame stays with your name