-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(browser): Always start navigation as root span #17648
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 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
13 changes: 13 additions & 0 deletions
13
...tion-tests/suites/tracing/browserTracingIntegration/interactions-navigation-click/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,13 @@ | ||
| import * as Sentry from '@sentry/browser'; | ||
|
|
||
| window.Sentry = Sentry; | ||
|
|
||
| Sentry.init({ | ||
| dsn: 'https://[email protected]/1337', | ||
| tracesSampleRate: 1, | ||
| integrations: [ | ||
| Sentry.browserTracingIntegration({ | ||
| _experiments: { enableInteractions: true }, | ||
| }), | ||
| ], | ||
| }); |
7 changes: 7 additions & 0 deletions
7
...n-tests/suites/tracing/browserTracingIntegration/interactions-navigation-click/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,7 @@ | ||
| // Clicking the navigate button will push a new history state, triggering navigation | ||
| document.querySelector('[data-test-id=navigate-button]').addEventListener('click', () => { | ||
| const loc = window.location; | ||
| const url = loc.href.includes('#nav') ? loc.pathname : `${loc.pathname}#nav`; | ||
|
|
||
| history.pushState({}, '', url); | ||
| }); |
9 changes: 9 additions & 0 deletions
9
...ests/suites/tracing/browserTracingIntegration/interactions-navigation-click/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,9 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="utf-8" /> | ||
| </head> | ||
| <body> | ||
| <button data-test-id="navigate-button">Navigate</button> | ||
| </body> | ||
| </html> |
45 changes: 45 additions & 0 deletions
45
...tion-tests/suites/tracing/browserTracingIntegration/interactions-navigation-click/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,45 @@ | ||
| import { expect } from '@playwright/test'; | ||
| import type { Event as SentryEvent } from '@sentry/core'; | ||
| import { sentryTest } from '../../../../utils/fixtures'; | ||
| import { | ||
| envelopeRequestParser, | ||
| getFirstSentryEnvelopeRequest, | ||
| shouldSkipTracingTest, | ||
| waitForTransactionRequest, | ||
| } from '../../../../utils/helpers'; | ||
|
|
||
| sentryTest( | ||
| 'click-triggered navigation should produce a root navigation transaction', | ||
| async ({ getLocalTestUrl, page }) => { | ||
| if (shouldSkipTracingTest()) { | ||
| sentryTest.skip(); | ||
| } | ||
|
|
||
| const url = await getLocalTestUrl({ testDir: __dirname }); | ||
|
|
||
| await page.goto(url); | ||
| await getFirstSentryEnvelopeRequest<SentryEvent>(page); | ||
|
|
||
| const interactionRequestPromise = waitForTransactionRequest( | ||
| page, | ||
| evt => evt.contexts?.trace?.op === 'ui.action.click', | ||
| ); | ||
| const navigationRequestPromise = waitForTransactionRequest(page, evt => evt.contexts?.trace?.op === 'navigation'); | ||
|
|
||
| await page.locator('[data-test-id=navigate-button]').click(); | ||
|
|
||
| const interactionEvent = envelopeRequestParser(await interactionRequestPromise); | ||
| const navigationEvent = envelopeRequestParser(await navigationRequestPromise); | ||
|
|
||
| // Navigation is root span, not a child span on the interaction | ||
| expect(interactionEvent.contexts?.trace?.op).toBe('ui.action.click'); | ||
| expect(navigationEvent.contexts?.trace?.op).toBe('navigation'); | ||
|
|
||
| expect(interactionEvent.contexts?.trace?.trace_id).not.toEqual(navigationEvent.contexts?.trace?.trace_id); | ||
|
|
||
| // does not contain a child navigation span | ||
| const interactionSpans = interactionEvent.spans || []; | ||
| const hasNavigationChild = interactionSpans.some(span => span.op === 'navigation' || span.op === 'http.server'); | ||
| expect(hasNavigationChild).toBeFalsy(); | ||
| }, | ||
| ); | ||
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.
l: can we use
waitForTransactionRequesthere, too? (I just think it's better practise to wait for transaction events rather than any event).