Repository navigation
test(browser): port browser tracing suites to span streaming #24888
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
msonnb
merged 7 commits into
ms/browser-tests-trace-semantics
from
ms/browser-tests-browser-tracing
Oct 9, 2026
+3,526
−3,240
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
131bc91
test(browser): port browser tracing suites to span streaming
msonnb 6cd2ac9
test(browser): retain static browser tracing counterparts
msonnb 0459707
test(browser): remove HTTP timings debug pause
msonnb 071e906
test(browser): use attribute constants in browser tracing suites
msonnb 7dab783
test(browser): synchronize tracing tests with telemetry
msonnb 7bb14c7
code review
msonnb 595871f
test(browser): address browser tracing bot review feedback
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
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
File renamed without changes.
File renamed without changes.
23 changes: 23 additions & 0 deletions
23
...tion-tests/suites/tracing/browserTracingIntegration/backgroundtab-pageload-static/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,23 @@ | ||
| import { PAGELOAD } from '@sentry/conventions/op'; | ||
| import { SENTRY_CANCELLATION_REASON } from '@sentry/conventions/attributes'; | ||
| import { expect } from '@playwright/test'; | ||
| import { sentryTest } from '../../../../utils/fixtures'; | ||
| import { envelopeRequestParser, shouldSkipTracingTest, waitForTransactionRequest } from '../../../../utils/helpers'; | ||
|
|
||
| sentryTest('should finish pageload transaction when the page goes background', async ({ getLocalTestUrl, page }) => { | ||
| if (shouldSkipTracingTest()) { | ||
| sentryTest.skip(); | ||
| } | ||
| const url = await getLocalTestUrl({ testDir: __dirname }); | ||
|
|
||
| const pageloadPromise = waitForTransactionRequest(page, event => event.contexts?.trace?.op === PAGELOAD); | ||
|
|
||
| await page.goto(url); | ||
| await page.locator('#go-background').click(); | ||
|
|
||
| const pageloadTransaction = envelopeRequestParser(await pageloadPromise); | ||
|
|
||
| expect(pageloadTransaction.contexts?.trace?.op).toBe(PAGELOAD); | ||
| expect(pageloadTransaction.contexts?.trace?.status).toBe('cancelled'); | ||
| expect(pageloadTransaction.contexts?.trace?.data?.[SENTRY_CANCELLATION_REASON]).toBe('document.hidden'); | ||
| }); |
18 changes: 0 additions & 18 deletions
18
...on-tests/suites/tracing/browserTracingIntegration/backgroundtab-pageload-streamed/test.ts
This file was deleted.
Oops, something went wrong.
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
22 changes: 11 additions & 11 deletions
22
...integration-tests/suites/tracing/browserTracingIntegration/backgroundtab-pageload/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,20 +1,20 @@ | ||
| import { PAGELOAD } from '@sentry/conventions/op'; | ||
| import { SENTRY_CANCELLATION_REASON } from '@sentry/conventions/attributes'; | ||
| import { expect } from '@playwright/test'; | ||
| import type { Event } from '@sentry/core'; | ||
| import { sentryTest } from '../../../../utils/fixtures'; | ||
| import { getFirstSentryEnvelopeRequest, shouldSkipTracingTest } from '../../../../utils/helpers'; | ||
| import { shouldSkipTracingTest } from '../../../../utils/helpers'; | ||
| import { getSpanOp, waitForStreamedSpan } from '../../../../utils/spanUtils'; | ||
|
|
||
| sentryTest('should finish pageload transaction when the page goes background', async ({ getLocalTestUrl, page }) => { | ||
| if (shouldSkipTracingTest()) { | ||
| sentryTest.skip(); | ||
| } | ||
| sentryTest('finishes streamed pageload span when the page goes background', async ({ getLocalTestUrl, page }) => { | ||
| sentryTest.skip(shouldSkipTracingTest()); | ||
| const url = await getLocalTestUrl({ testDir: __dirname }); | ||
| const pageloadSpanPromise = waitForStreamedSpan(page, span => getSpanOp(span) === PAGELOAD); | ||
|
|
||
| await page.goto(url); | ||
| await page.locator('#go-background').click(); | ||
| const pageloadSpan = await pageloadSpanPromise; | ||
|
|
||
| const pageloadTransaction = await getFirstSentryEnvelopeRequest<Event>(page); | ||
|
|
||
| expect(pageloadTransaction.contexts?.trace?.op).toBe('pageload'); | ||
| expect(pageloadTransaction.contexts?.trace?.status).toBe('cancelled'); | ||
| expect(pageloadTransaction.contexts?.trace?.data?.['sentry.cancellation_reason']).toBe('document.hidden'); | ||
| expect(getSpanOp(pageloadSpan)).toBe(PAGELOAD); | ||
| expect(pageloadSpan.status).toBe('ok'); | ||
| expect(pageloadSpan.attributes[SENTRY_CANCELLATION_REASON]?.value).toBe('document.hidden'); | ||
| }); | ||
54 changes: 21 additions & 33 deletions
54
...packages/browser-integration-tests/suites/tracing/browserTracingIntegration/error/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,47 +1,35 @@ | ||
| import { PAGELOAD } from '@sentry/conventions/op'; | ||
| import { URL_PATH } from '@sentry/conventions/attributes'; | ||
| import { expect } from '@playwright/test'; | ||
| import type { Event } from '@sentry/core'; | ||
| import { sentryTest } from '../../../../utils/fixtures'; | ||
| import { | ||
| getMultipleSentryEnvelopeRequests, | ||
| envelopeRequestParser, | ||
| waitForErrorRequest, | ||
| runScriptInSandbox, | ||
| shouldSkipTracingTest, | ||
| } from '../../../../utils/helpers'; | ||
| import { collectStreamedSpans, getSpanOp, waitForStreamedSpan } from '../../../../utils/spanUtils'; | ||
|
|
||
| sentryTest( | ||
| 'should put the pageload transaction name onto an error event caught during pageload', | ||
| 'puts the page path onto an error caught during pageload', | ||
| async ({ getLocalTestUrl, page, browserName }) => { | ||
| if (browserName === 'webkit') { | ||
| // This test fails on Webkit as errors thrown from `runScriptInSandbox` are Script Errors and skipped by Sentry | ||
| sentryTest.skip(); | ||
| } | ||
|
|
||
| if (shouldSkipTracingTest()) { | ||
| sentryTest.skip(); | ||
| } | ||
|
|
||
| // WebKit treats errors from runScriptInSandbox as Script Errors, which Sentry skips. | ||
| sentryTest.skip(shouldSkipTracingTest() || browserName === 'webkit'); | ||
| const url = await getLocalTestUrl({ testDir: __dirname }); | ||
|
|
||
| const errorEventsPromise = getMultipleSentryEnvelopeRequests<Event>(page, 2); | ||
|
|
||
| const spans = collectStreamedSpans(page); | ||
| const pageloadPromise = waitForStreamedSpan(page, span => getSpanOp(span) === PAGELOAD); | ||
| const errorPromise = waitForErrorRequest(page); | ||
| await page.goto(url); | ||
|
|
||
| await runScriptInSandbox(page, { | ||
| content: ` | ||
| throw new Error('Error during pageload'); | ||
| `, | ||
| }); | ||
|
|
||
| const [e1, e2] = await errorEventsPromise; | ||
|
|
||
| const pageloadTxnEvent = e1.type === 'transaction' ? e1 : e2; | ||
| const errorEvent = e1.type === 'transaction' ? e2 : e1; | ||
|
|
||
| expect(pageloadTxnEvent.contexts?.trace?.op).toEqual('pageload'); | ||
| expect(pageloadTxnEvent.spans?.length).toBeGreaterThan(0); | ||
| expect(errorEvent.exception?.values?.[0]).toBeDefined(); | ||
|
|
||
| expect(pageloadTxnEvent.transaction?.endsWith('index.html')).toBe(true); | ||
|
|
||
| expect(errorEvent.transaction).toEqual(pageloadTxnEvent.transaction); | ||
| await runScriptInSandbox(page, { content: "throw new Error('Error during pageload');" }); | ||
| const [pageload, errorRequest] = await Promise.all([pageloadPromise, errorPromise]); | ||
| await page.evaluate(() => (window as any).Sentry.flush()); | ||
| expect(getSpanOp(pageload)).toBe(PAGELOAD); | ||
| expect(spans.filter(span => !span.is_segment)).not.toHaveLength(0); | ||
| const error = envelopeRequestParser<Event>(errorRequest); | ||
| expect(error.exception?.values?.[0]).toBeDefined(); | ||
| expect(pageload.name).toBe('Pageload'); | ||
| expect(error.transaction).toBe('/index.html'); | ||
| expect(error.transaction).toBe(pageload.attributes[URL_PATH]?.value); | ||
| }, | ||
| ); |
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
File renamed without changes.
75 changes: 75 additions & 0 deletions
75
...er-integration-tests/suites/tracing/browserTracingIntegration/http-timings-static/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,75 @@ | ||
| import { PAGELOAD, HTTP_CLIENT } from '@sentry/conventions/op'; | ||
| import { | ||
| HTTP_REQUEST_REDIRECT_START, | ||
| HTTP_REQUEST_REDIRECT_END, | ||
| HTTP_REQUEST_WORKER_START, | ||
| HTTP_REQUEST_FETCH_START, | ||
| HTTP_REQUEST_DOMAIN_LOOKUP_START, | ||
| HTTP_REQUEST_DOMAIN_LOOKUP_END, | ||
| HTTP_REQUEST_CONNECT_START, | ||
| HTTP_REQUEST_SECURE_CONNECTION_START, | ||
| HTTP_REQUEST_CONNECTION_END, | ||
| HTTP_REQUEST_REQUEST_START, | ||
| HTTP_REQUEST_RESPONSE_START, | ||
| HTTP_REQUEST_RESPONSE_END, | ||
| HTTP_REQUEST_TIME_TO_FIRST_BYTE, | ||
| NETWORK_PROTOCOL_VERSION, | ||
| } from '@sentry/conventions/attributes'; | ||
| import { expect } from '@playwright/test'; | ||
| import { sentryTest } from '../../../../utils/fixtures'; | ||
| import { envelopeRequestParser, shouldSkipTracingTest, waitForTransactionRequest } from '../../../../utils/helpers'; | ||
|
|
||
| sentryTest('creates fetch spans with http timing', async ({ browserName, getLocalTestUrl, page }) => { | ||
| const supportedBrowsers = ['chromium', 'firefox']; | ||
|
|
||
| if (shouldSkipTracingTest() || !supportedBrowsers.includes(browserName)) { | ||
| sentryTest.skip(); | ||
| } | ||
| await page.route('http://sentry-test-site.example/*', async route => { | ||
| const request = route.request(); | ||
| const postData = await request.postDataJSON(); | ||
|
|
||
| await route.fulfill({ | ||
| status: 200, | ||
| contentType: 'application/json', | ||
| body: JSON.stringify(Object.assign({ id: 1 }, postData)), | ||
| }); | ||
| }); | ||
|
|
||
| const url = await getLocalTestUrl({ testDir: __dirname }); | ||
|
|
||
| const pageloadPromise = waitForTransactionRequest(page, event => event.contexts?.trace?.op === PAGELOAD); | ||
| await page.goto(url); | ||
| const tracingEvent = envelopeRequestParser(await pageloadPromise); | ||
|
|
||
| const requestSpans = tracingEvent.spans?.filter(({ op }) => op === HTTP_CLIENT); | ||
|
|
||
| expect(requestSpans).toHaveLength(3); | ||
|
|
||
| requestSpans?.forEach((span, index) => | ||
| expect(span).toMatchObject({ | ||
| description: `GET http://sentry-test-site.example/${index}`, | ||
| parent_span_id: tracingEvent.contexts?.trace?.span_id, | ||
| span_id: expect.stringMatching(/[a-f\d]{16}/), | ||
| start_timestamp: expect.any(Number), | ||
| timestamp: expect.any(Number), | ||
| trace_id: tracingEvent.contexts?.trace?.trace_id, | ||
| data: expect.objectContaining({ | ||
| [HTTP_REQUEST_REDIRECT_START]: expect.any(Number), | ||
| [HTTP_REQUEST_REDIRECT_END]: expect.any(Number), | ||
| [HTTP_REQUEST_WORKER_START]: expect.any(Number), | ||
| [HTTP_REQUEST_FETCH_START]: expect.any(Number), | ||
| [HTTP_REQUEST_DOMAIN_LOOKUP_START]: expect.any(Number), | ||
| [HTTP_REQUEST_DOMAIN_LOOKUP_END]: expect.any(Number), | ||
| [HTTP_REQUEST_CONNECT_START]: expect.any(Number), | ||
| [HTTP_REQUEST_SECURE_CONNECTION_START]: expect.any(Number), | ||
| [HTTP_REQUEST_CONNECTION_END]: expect.any(Number), | ||
| [HTTP_REQUEST_REQUEST_START]: expect.any(Number), | ||
| [HTTP_REQUEST_RESPONSE_START]: expect.any(Number), | ||
| [HTTP_REQUEST_RESPONSE_END]: expect.any(Number), | ||
| [HTTP_REQUEST_TIME_TO_FIRST_BYTE]: expect.any(Number), | ||
| [NETWORK_PROTOCOL_VERSION]: expect.any(String), | ||
| }), | ||
| }), | ||
| ); | ||
| }); |
64 changes: 0 additions & 64 deletions
64
...-integration-tests/suites/tracing/browserTracingIntegration/http-timings-streamed/test.ts
This file was deleted.
Oops, something went wrong.
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.