-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
fix(core): Account for clock drift on every timestampInSeconds call
#23054
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
Draft
Lms24
wants to merge
6
commits into
develop
Choose a base branch
from
lms/fix-core-browser-timestampInSeconds-offset-clockdrift
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ded4f36
fix(core): Account for clock drift on every `timestampInSeconds` call
Lms24 793d21c
fix(core): Resolve monotonic times against the origin they were measu…
Lms24 1a9120e
fix(browser): Convert late-reported performance entries against their…
Lms24 666afe6
fix(browser): Resolve every performance entry against its own time or…
Lms24 86f158a
fix(browser): Check for clock drift when the page is hidden and shown
Lms24 7c6a950
fix(core): Lower the clock drift threshold to 15 seconds
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
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
79 changes: 79 additions & 0 deletions
79
packages/browser-utils/test/performance/addPerformanceEntries.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,79 @@ | ||
| import type { Span } from '@sentry/core'; | ||
| import * as SentryCore from '@sentry/core'; | ||
| import { getClient, getMainCarrier, SentrySpan, setCurrentClient, spanToJSON } from '@sentry/core'; | ||
| import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; | ||
| import { addPerformanceEntries } from '../../src/performance/entries'; | ||
| import { WINDOW } from '../../src/types'; | ||
| import { getDefaultClientOptions, TestClient } from '../utils/TestClient'; | ||
|
|
||
| vi.mock('@sentry/core', async () => { | ||
| const actual = await vi.importActual('@sentry/core'); | ||
| return { | ||
| ...actual, | ||
| browserPerformanceTimeOrigin: vi.fn(), | ||
| }; | ||
| }); | ||
|
|
||
| const pageloadOriginMs = 1_000_000; | ||
| const sleepDurationMs = 3_600_000; | ||
| // The monotonic time from which the SDK applies the origin it re-derived after the device slept. | ||
| const correctionFromMs = 10_000; | ||
|
|
||
| describe('addPerformanceEntries', () => { | ||
| beforeEach(() => { | ||
| getMainCarrier().__SENTRY__ = undefined; | ||
| const client = new TestClient(getDefaultClientOptions({ tracesSampleRate: 1 })); | ||
| setCurrentClient(client); | ||
| client.init(); | ||
|
|
||
| vi.mocked(SentryCore.browserPerformanceTimeOrigin).mockImplementation((monotonicTimeInMs = 0) => | ||
| monotonicTimeInMs < correctionFromMs ? pageloadOriginMs : pageloadOriginMs + sleepDurationMs, | ||
| ); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| vi.restoreAllMocks(); | ||
| vi.unstubAllGlobals(); | ||
| }); | ||
|
|
||
| it('keeps the resource spans of a navigation that happens after a clock drift correction', () => { | ||
| const resourceStartTime = 12_000; | ||
| vi.stubGlobal('addEventListener', vi.fn()); | ||
| vi.stubGlobal('location', { origin: 'https://example.com' }); | ||
| vi.spyOn(WINDOW.performance, 'getEntries').mockReturnValue([ | ||
| { | ||
| entryType: 'resource', | ||
| name: 'https://example.com/app.js', | ||
| initiatorType: 'script', | ||
| startTime: resourceStartTime, | ||
| duration: 100, | ||
| responseEnd: resourceStartTime + 100, | ||
| toJSON: () => ({}), | ||
| } as PerformanceResourceTiming, | ||
| ]); | ||
|
|
||
| const navigationStartTimestamp = (pageloadOriginMs + sleepDurationMs + resourceStartTime - 50) / 1000; | ||
| const span = new SentrySpan({ | ||
| op: 'navigation', | ||
| name: '/next', | ||
| sampled: true, | ||
| startTimestamp: navigationStartTimestamp, | ||
| }); | ||
|
|
||
| const endedSpans: Span[] = []; | ||
| getClient()?.on('spanEnd', endedSpan => void endedSpans.push(endedSpan)); | ||
|
|
||
| addPerformanceEntries(span, { ignoreResourceSpans: [] }); | ||
|
|
||
| expect(endedSpans.map(spanToJSON)).toEqual([ | ||
| expect.objectContaining({ | ||
| start_timestamp: (pageloadOriginMs + sleepDurationMs + resourceStartTime) / 1000, | ||
| end_timestamp: (pageloadOriginMs + sleepDurationMs + resourceStartTime + 100) / 1000, | ||
| attributes: expect.objectContaining({ | ||
| 'sentry.op': 'resource.script', | ||
| 'http.request.response_end': (pageloadOriginMs + sleepDurationMs + resourceStartTime + 100) / 1000, | ||
| }), | ||
| }), | ||
| ]); | ||
| }); | ||
| }); |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.