-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(browser): Avoid recording long task spans starting before their parent span #14183
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 2 commits
Commits
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
19 changes: 19 additions & 0 deletions
19
...ation-tests/suites/tracing/browserTracingIntegration/long-tasks-before-navigation/init.js
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,19 @@ | ||
import * as Sentry from '@sentry/browser'; | ||
|
||
window.Sentry = Sentry; | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/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 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,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 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,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 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,27 @@ | ||
import type { Event } from '@sentry/types'; | ||
import { expect } from '@playwright/test'; | ||
|
||
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 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
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.
small refactor: I switched from manually starting and ending the span to using the
startAndEndSpan
helper which does just that. However, the helper would also adjust the navigation span start time stamp if the stamp was started beforehand.I medium-strongly feel we should not adjust this start time stamp b/c the long task might have nothing to do with the navigation but it would look like it otherwise.
If reviewers prefer the other way around (i.e. actually record the span and adjust the transaction start time), I'm also fine with that.