-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(browser): Avoid recording long task spans starting before their p…
…arent span (#14183) - check for the start time stamp and drops long task spans starting before a _navigation_ spans started. - refactor the start and end logic a bit to compensate for bundle size increase (see comment) - add a regression test that previously would fail
- Loading branch information
Showing
7 changed files
with
95 additions
and
15 deletions.
There are no files selected for viewing
This file contains 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
19 changes: 19 additions & 0 deletions
19
...ation-tests/suites/tracing/browserTracingIntegration/long-tasks-before-navigation/init.js
This file contains 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,19 @@ | ||
import * as Sentry from '@sentry/browser'; | ||
|
||
window.Sentry = Sentry; | ||
|
||
Sentry.init({ | ||
dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
integrations: [ | ||
Sentry.browserTracingIntegration({ | ||
idleTimeout: 9000, | ||
enableLongAnimationFrame: false, | ||
instrumentPageLoad: false, | ||
instrumentNavigation: true, | ||
enableInp: false, | ||
enableLongTask: true, | ||
}), | ||
], | ||
tracesSampleRate: 1, | ||
debug: true, | ||
}); |
17 changes: 17 additions & 0 deletions
17
...on-tests/suites/tracing/browserTracingIntegration/long-tasks-before-navigation/subject.js
This file contains 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,17 @@ | ||
const longTaskButton = document.getElementById('myButton'); | ||
|
||
longTaskButton?.addEventListener('click', () => { | ||
const startTime = Date.now(); | ||
|
||
function getElapsed() { | ||
const time = Date.now(); | ||
return time - startTime; | ||
} | ||
|
||
while (getElapsed() < 500) { | ||
// | ||
} | ||
|
||
// trigger a navigation in the same event loop tick | ||
window.history.pushState({}, '', '/#myHeading'); | ||
}); |
13 changes: 13 additions & 0 deletions
13
...tests/suites/tracing/browserTracingIntegration/long-tasks-before-navigation/template.html
This file contains 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,13 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
</head> | ||
<body> | ||
<div>Rendered Before Long Task</div> | ||
<script src="https://example.com/path/to/script.js"></script> | ||
|
||
<button id="myButton">Start long task</button> | ||
<h1 id="myHeading">Heading</h1> | ||
</body> | ||
</html> |
27 changes: 27 additions & 0 deletions
27
...ation-tests/suites/tracing/browserTracingIntegration/long-tasks-before-navigation/test.ts
This file contains 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,27 @@ | ||
import { expect } from '@playwright/test'; | ||
import type { Event } from '@sentry/types'; | ||
|
||
import { sentryTest } from '../../../../utils/fixtures'; | ||
import { getFirstSentryEnvelopeRequest, shouldSkipTracingTest } from '../../../../utils/helpers'; | ||
|
||
sentryTest( | ||
"doesn't capture long task spans starting before a navigation in the navigation transaction", | ||
async ({ browserName, getLocalTestPath, page }) => { | ||
// Long tasks only work on chrome | ||
if (shouldSkipTracingTest() || browserName !== 'chromium') { | ||
sentryTest.skip(); | ||
} | ||
const url = await getLocalTestPath({ testDir: __dirname }); | ||
|
||
await page.goto(url); | ||
|
||
await page.locator('#myButton').click(); | ||
|
||
const navigationTransactionEvent = await getFirstSentryEnvelopeRequest<Event>(page, url); | ||
|
||
expect(navigationTransactionEvent.contexts?.trace?.op).toBe('navigation'); | ||
|
||
const longTaskSpans = navigationTransactionEvent?.spans?.filter(span => span.op === 'ui.long-task'); | ||
expect(longTaskSpans).toHaveLength(0); | ||
}, | ||
); |
This file contains 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 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