Skip to content

Commit c0cc99e

Browse files
msonnbcodex
andcommitted
test(browser): port browser tracing suites to span streaming
Co-Authored-By: GPT-6 <codex@openai.com>
1 parent fe7078d commit c0cc99e

184 files changed

Lines changed: 1688 additions & 4326 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/async-spans/init.js‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import * as Sentry from '@sentry/browser';
33
window.Sentry = Sentry;
44

55
Sentry.init({
6-
traceLifecycle: 'static',
76
dsn: 'https://public@dsn.ingest.sentry.io/1337',
87
integrations: [Sentry.browserTracingIntegration()],
98
tracesSampleRate: 1,

‎dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/async-spans/test.ts‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { expect } from '@playwright/test';
2-
import type { Event } from '@sentry/core';
32
import { sentryTest } from '../../../../utils/fixtures';
4-
import { getFirstSentryEnvelopeRequest, shouldSkipTracingTest } from '../../../../utils/helpers';
3+
import { shouldSkipTracingTest } from '../../../../utils/helpers';
54

65
type WindowWithSpan = Window & {
76
firstWaitingSpan: any;
@@ -19,8 +18,7 @@ sentryTest(
1918
const url = await getLocalTestUrl({ testDir: __dirname });
2019
await page.goto(url);
2120

22-
const envelope = await getFirstSentryEnvelopeRequest<Event>(page);
23-
expect(envelope).toBeDefined();
21+
await page.waitForFunction(() => !!(window as unknown as WindowWithSpan).secondWaitingSpan);
2422

2523
const firstWaitingSpanValue = await page.evaluate(
2624
() => (window as unknown as WindowWithSpan).firstWaitingSpan.name,

‎dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/backgroundtab-custom/init.js‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import * as Sentry from '@sentry/browser';
33
window.Sentry = Sentry;
44

55
Sentry.init({
6-
traceLifecycle: 'static',
76
dsn: 'https://public@dsn.ingest.sentry.io/1337',
87
integrations: [
98
Sentry.browserTracingIntegration({

‎dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/backgroundtab-custom/test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { StreamedSpanJSON } from '@sentry/core';
33
import { sentryTest } from '../../../../utils/fixtures';
44
import { shouldSkipTracingTest } from '../../../../utils/helpers';
55

6-
sentryTest('should finish a custom transaction when the page goes background', async ({ getLocalTestUrl, page }) => {
6+
sentryTest('should finish a custom span when the page goes background', async ({ getLocalTestUrl, page }) => {
77
if (shouldSkipTracingTest()) {
88
sentryTest.skip();
99
}

‎dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/backgroundtab-pageload-streamed/subject.js‎

Lines changed: 0 additions & 8 deletions
This file was deleted.

‎dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/backgroundtab-pageload-streamed/template.html‎

Lines changed: 0 additions & 9 deletions
This file was deleted.

‎dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/backgroundtab-pageload-streamed/test.ts‎

Lines changed: 0 additions & 18 deletions
This file was deleted.

dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/navigation-streamed/init.js renamed to dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/backgroundtab-pageload/init.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ window.Sentry = Sentry;
44

55
Sentry.init({
66
dsn: 'https://public@dsn.ingest.sentry.io/1337',
7-
integrations: [Sentry.browserTracingIntegration(), Sentry.spanStreamingIntegration()],
7+
integrations: [Sentry.browserTracingIntegration()],
88
tracesSampleRate: 1,
99
});
Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
import { expect } from '@playwright/test';
2-
import type { Event } from '@sentry/core';
32
import { sentryTest } from '../../../../utils/fixtures';
4-
import { getFirstSentryEnvelopeRequest, shouldSkipTracingTest } from '../../../../utils/helpers';
3+
import { shouldSkipTracingTest } from '../../../../utils/helpers';
4+
import { getSpanOp, waitForStreamedSpan } from '../../../../utils/spanUtils';
55

6-
sentryTest('should finish pageload transaction when the page goes background', async ({ getLocalTestUrl, page }) => {
7-
if (shouldSkipTracingTest()) {
8-
sentryTest.skip();
9-
}
6+
sentryTest('finishes streamed pageload span when the page goes background', async ({ getLocalTestUrl, page }) => {
7+
sentryTest.skip(shouldSkipTracingTest());
108
const url = await getLocalTestUrl({ testDir: __dirname });
9+
const pageloadSpanPromise = waitForStreamedSpan(page, span => getSpanOp(span) === 'pageload');
1110

1211
await page.goto(url);
1312
await page.locator('#go-background').click();
13+
const pageloadSpan = await pageloadSpanPromise;
1414

15-
const pageloadTransaction = await getFirstSentryEnvelopeRequest<Event>(page);
16-
17-
expect(pageloadTransaction.contexts?.trace?.op).toBe('pageload');
18-
expect(pageloadTransaction.contexts?.trace?.status).toBe('cancelled');
19-
expect(pageloadTransaction.contexts?.trace?.data?.['sentry.cancellation_reason']).toBe('document.hidden');
15+
expect(getSpanOp(pageloadSpan)).toBe('pageload');
16+
expect(pageloadSpan.status).toBe('ok');
17+
expect(pageloadSpan.attributes['sentry.cancellation_reason']?.value).toBe('document.hidden');
2018
});

‎dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/error/test.ts‎

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,32 @@ import { expect } from '@playwright/test';
22
import type { Event } from '@sentry/core';
33
import { sentryTest } from '../../../../utils/fixtures';
44
import {
5-
getMultipleSentryEnvelopeRequests,
5+
envelopeRequestParser,
6+
waitForErrorRequest,
67
runScriptInSandbox,
78
shouldSkipTracingTest,
89
} from '../../../../utils/helpers';
10+
import { collectStreamedSpans, getSpanOp, waitForStreamedSpan } from '../../../../utils/spanUtils';
911

1012
sentryTest(
11-
'should put the pageload transaction name onto an error event caught during pageload',
13+
'puts the page path onto an error caught during pageload',
1214
async ({ getLocalTestUrl, page, browserName }) => {
13-
if (browserName === 'webkit') {
14-
// This test fails on Webkit as errors thrown from `runScriptInSandbox` are Script Errors and skipped by Sentry
15-
sentryTest.skip();
16-
}
17-
18-
if (shouldSkipTracingTest()) {
19-
sentryTest.skip();
20-
}
21-
15+
// WebKit treats errors from runScriptInSandbox as Script Errors, which Sentry skips.
16+
sentryTest.skip(shouldSkipTracingTest() || browserName === 'webkit');
2217
const url = await getLocalTestUrl({ testDir: __dirname });
23-
24-
const errorEventsPromise = getMultipleSentryEnvelopeRequests<Event>(page, 2);
25-
18+
const spans = collectStreamedSpans(page);
19+
const pageloadPromise = waitForStreamedSpan(page, span => getSpanOp(span) === 'pageload');
20+
const errorPromise = waitForErrorRequest(page);
2621
await page.goto(url);
27-
28-
await runScriptInSandbox(page, {
29-
content: `
30-
throw new Error('Error during pageload');
31-
`,
32-
});
33-
34-
const [e1, e2] = await errorEventsPromise;
35-
36-
const pageloadTxnEvent = e1.type === 'transaction' ? e1 : e2;
37-
const errorEvent = e1.type === 'transaction' ? e2 : e1;
38-
39-
expect(pageloadTxnEvent.contexts?.trace?.op).toEqual('pageload');
40-
expect(pageloadTxnEvent.spans?.length).toBeGreaterThan(0);
41-
expect(errorEvent.exception?.values?.[0]).toBeDefined();
42-
43-
expect(pageloadTxnEvent.transaction?.endsWith('index.html')).toBe(true);
44-
45-
expect(errorEvent.transaction).toEqual(pageloadTxnEvent.transaction);
22+
await runScriptInSandbox(page, { content: "throw new Error('Error during pageload');" });
23+
const [pageload, errorRequest] = await Promise.all([pageloadPromise, errorPromise]);
24+
await page.evaluate(() => (window as any).Sentry.flush());
25+
expect(getSpanOp(pageload)).toBe('pageload');
26+
expect(spans.filter(span => !span.is_segment)).not.toHaveLength(0);
27+
const error = envelopeRequestParser<Event>(errorRequest);
28+
expect(error.exception?.values?.[0]).toBeDefined();
29+
expect(pageload.name).toBe('Pageload');
30+
expect(error.transaction).toBe('/index.html');
31+
expect(error.transaction).toBe(pageload.attributes['url.path']?.value);
4632
},
4733
);

0 commit comments

Comments
 (0)