Repository navigation
test(browser): port requests and web vitals to span streaming #24886
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
Open
msonnb
wants to merge
4
commits into
ms/browser-tests-browser-tracing
from
ms/browser-tests-requests-web-vitals
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
aef8e8d
test(browser): port requests and web vitals to span streaming
msonnb 468b4a6
test(browser): retain static request and metric counterparts
msonnb 52e9455
test(browser): wait for LCP candidates and use attribute constants
msonnb 0949ba8
test(browser): tighten request and web vital assertions
msonnb 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
18 changes: 9 additions & 9 deletions
18
dev-packages/browser-integration-tests/suites/tracing/interactions/disabled/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 |
|---|---|---|
| @@ -1,19 +1,19 @@ | ||
| import { SENTRY_ORIGIN } from '@sentry/conventions/attributes'; | ||
| import { expect } from '@playwright/test'; | ||
| import type { Event as SentryEvent } from '@sentry/core'; | ||
| import { sentryTest } from '../../../../utils/fixtures'; | ||
| import { countEnvelopes, getFirstSentryEnvelopeRequest, shouldSkipTracingTest } from '../../../../utils/helpers'; | ||
| import { hidePage, shouldSkipTracingTest } from '../../../../utils/helpers'; | ||
| import { collectStreamedSpans, getSpanOp, waitForStreamedSpan } from '../../../../utils/spanUtils'; | ||
|
|
||
| sentryTest('does not capture interaction spans without the integration', async ({ getLocalTestUrl, page }) => { | ||
| sentryTest.skip(shouldSkipTracingTest()); | ||
|
|
||
| const spans = collectStreamedSpans(page); | ||
| const pageloadPromise = waitForStreamedSpan(page, span => span.is_segment && getSpanOp(span) === 'pageload'); | ||
| const url = await getLocalTestUrl({ testDir: __dirname }); | ||
|
|
||
| await page.goto(url); | ||
| await getFirstSentryEnvelopeRequest<SentryEvent>(page); | ||
|
|
||
| const countPromise = countEnvelopes(page, { envelopeType: 'transaction', timeout: 2000 }); | ||
|
|
||
| await pageloadPromise; | ||
| await page.locator('[data-test-id=interaction-button]').click(); | ||
| await hidePage(page); | ||
| await page.evaluate(() => (window as any).Sentry.flush()); | ||
|
|
||
| expect(await countPromise).toBe(0); | ||
| expect(spans.filter(span => span.attributes[SENTRY_ORIGIN]?.value === 'auto.browser.interactions')).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
63 changes: 26 additions & 37 deletions
63
dev-packages/browser-integration-tests/suites/tracing/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 |
|---|---|---|
| @@ -1,39 +1,28 @@ | ||
| import { expect } from '@playwright/test'; | ||
| import { sentryTest } from '../../../../utils/fixtures'; | ||
| import { envelopeRequestParser, 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 waitForTransactionRequest(page); // "pageload" root span | ||
|
|
||
| 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(); | ||
| }, | ||
| ); | ||
| import { shouldSkipTracingTest } from '../../../../utils/helpers'; | ||
| import { collectStreamedSpans, getSpanOp, waitForStreamedSpan } from '../../../../utils/spanUtils'; | ||
|
|
||
| sentryTest('starts a root navigation segment when a click triggers navigation', async ({ getLocalTestUrl, page }) => { | ||
| sentryTest.skip(shouldSkipTracingTest()); | ||
| const spans = collectStreamedSpans(page); | ||
| const pageloadPromise = waitForStreamedSpan(page, span => span.is_segment && getSpanOp(span) === 'pageload'); | ||
| const url = await getLocalTestUrl({ testDir: __dirname }); | ||
| await page.goto(url); | ||
| await pageloadPromise; | ||
|
|
||
| const interactionPromise = waitForStreamedSpan( | ||
| page, | ||
| span => span.is_segment && getSpanOp(span) === 'ui.action.click', | ||
| ); | ||
| const navigationPromise = waitForStreamedSpan(page, span => span.is_segment && getSpanOp(span) === 'navigation'); | ||
| await page.locator('[data-test-id=navigate-button]').click(); | ||
| const [interaction, navigation] = await Promise.all([interactionPromise, navigationPromise]); | ||
| await page.evaluate(() => (window as any).Sentry.flush()); | ||
|
|
||
| expect(navigation.is_segment).toBe(true); | ||
| expect(navigation).not.toHaveProperty('parent_span_id'); | ||
| expect(navigation.trace_id).not.toBe(interaction.trace_id); | ||
| const children = spans.filter(span => span.parent_span_id === interaction.span_id); | ||
| expect(children.filter(span => ['navigation', 'http.server'].includes(getSpanOp(span) ?? ''))).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
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
45 changes: 16 additions & 29 deletions
45
...ckages/browser-integration-tests/suites/tracing/metrics/connection-rtt-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 |
|---|---|---|
| @@ -1,37 +1,24 @@ | ||
| import { expect } from '@playwright/test'; | ||
| import type { Event } from '@sentry/core'; | ||
| import { sentryTest } from '../../../../utils/fixtures'; | ||
| import { envelopeRequestParser, shouldSkipTracingTest, waitForTransactionRequest } from '../../../../utils/helpers'; | ||
| import { shouldSkipTracingTest } from '../../../../utils/helpers'; | ||
| import { waitForStreamedSpanAndTraceHeaderOnUrl } from '../../../../utils/spanUtils'; | ||
| import { | ||
| BROWSER_WEB_VITAL_FCP_VALUE, | ||
| BROWSER_WEB_VITAL_TTFB_VALUE, | ||
| NETWORK_CONNECTION_RTT, | ||
| } from '@sentry/conventions/attributes'; | ||
|
|
||
| sentryTest.beforeEach(({ browserName }) => { | ||
| if (shouldSkipTracingTest() || browserName !== 'chromium') { | ||
| sentryTest.skip(); | ||
| } | ||
| }); | ||
|
|
||
| // `connection.rtt` is recorded as a measurement, which is only flushed on the pageload | ||
| // transaction. It must not leak onto navigation transactions. | ||
| sentryTest( | ||
| 'records `connection.rtt` as a measurement on pageload but not on navigation transactions', | ||
| async ({ getLocalTestUrl, page }) => { | ||
| const pageloadRequestPromise = waitForTransactionRequest(page, event => event.contexts?.trace?.op === 'pageload'); | ||
| 'records connection RTT on pageload and navigation spans', | ||
| async ({ getLocalTestUrl, page, browserName }) => { | ||
| sentryTest.skip(shouldSkipTracingTest() || browserName !== 'chromium'); | ||
| const url = await getLocalTestUrl({ testDir: __dirname }); | ||
| await page.goto(url); | ||
|
|
||
| const pageloadRequest = envelopeRequestParser(await pageloadRequestPromise) as Event; | ||
|
|
||
| const navigationRequestPromise = waitForTransactionRequest( | ||
| page, | ||
| event => event.contexts?.trace?.op === 'navigation', | ||
| ); | ||
| await page.goto(`${url}#foo`); | ||
|
|
||
| const navigationRequest = envelopeRequestParser(await navigationRequestPromise) as Event; | ||
|
|
||
| expect(pageloadRequest.contexts?.trace?.op).toBe('pageload'); | ||
| expect(navigationRequest.contexts?.trace?.op).toBe('navigation'); | ||
| const [pageload] = await waitForStreamedSpanAndTraceHeaderOnUrl(page, url); | ||
| const [navigation] = await waitForStreamedSpanAndTraceHeaderOnUrl(page, `${url}#foo`); | ||
|
|
||
| expect(pageloadRequest.measurements?.['connection.rtt']?.value).toBeDefined(); | ||
| expect(navigationRequest.measurements?.['connection.rtt']).toBeUndefined(); | ||
| expect(pageload.attributes[NETWORK_CONNECTION_RTT]).toEqual({ type: 'integer', value: 0 }); | ||
| expect(navigation.attributes[NETWORK_CONNECTION_RTT]).toEqual(pageload.attributes[NETWORK_CONNECTION_RTT]); | ||
| expect(navigation.attributes[BROWSER_WEB_VITAL_FCP_VALUE]).toBeUndefined(); | ||
| expect(navigation.attributes[BROWSER_WEB_VITAL_TTFB_VALUE]).toBeUndefined(); | ||
| }, | ||
| ); | ||
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.
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.
hmm actually not sure if sending connction.rtt on navigation spans is an SDK bug or expected behaviour now? probably worth looking into. if it's a bug, I'm also fine with merging the test as-is and fixing it in a follow-up.