Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
import { expect } from '@playwright/test';
import { IncrementalSource } from '@sentry/rrweb';
import { sentryTest } from '../../../../utils/fixtures';
import { getReplayRecordingContent, shouldSkipReplayTest, waitForReplayRequest } from '../../../../utils/replayHelpers';
import type { RecordingSnapshot } from '../../../../utils/replayHelpers';
import {
collectReplayRequests,
getReplayRecordingContent,
shouldSkipReplayTest,
waitForReplayRequest,
} from '../../../../utils/replayHelpers';

function isCanvasMutation(snapshot: RecordingSnapshot): boolean {
return 'source' in snapshot.data && snapshot.data.source === IncrementalSource.CanvasMutation;
}

sentryTest('can record canvas', async ({ getLocalTestUrl, page, browserName }) => {
if (shouldSkipReplayTest() || browserName === 'webkit' || (process.env.PW_BUNDLE || '').startsWith('bundle')) {
sentryTest.skip();
}

const reqPromise0 = waitForReplayRequest(page, 0);
const reqPromise1 = waitForReplayRequest(page, 1);
const reqPromise2 = waitForReplayRequest(page, 2);

const url = await getLocalTestUrl({ testDir: __dirname });

Expand All @@ -25,10 +34,13 @@ sentryTest('can record canvas', async ({ getLocalTestUrl, page, browserName }) =
},
]);

await Promise.all([page.click('#draw'), reqPromise1]);
// The canvas is sampled on a timer, so its snapshot is in the segment of the click or in a later one.
const canvasRequestsPromise = collectReplayRequests(page, snapshots => snapshots.some(isCanvasMutation));

await page.click('#draw');

const { incrementalSnapshots } = getReplayRecordingContent(await reqPromise2);
expect(incrementalSnapshots).toEqual(
const { replayRecordingSnapshots } = await canvasRequestsPromise;
expect(replayRecordingSnapshots).toEqual(
expect.arrayContaining([
{
data: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ sentryTest(
const reqPromise1 = waitForReplayRequest(page, 1);
const reqPromise2 = waitForReplayRequest(page, 2);
const reqPromise3 = waitForReplayRequest(page, 3);
const reqPromise4 = waitForReplayRequest(page, 4);
const reqPromise5 = waitForReplayRequest(page, 5);
const reqPromise6 = waitForReplayRequest(page, 6);
const reqPromise7 = waitForReplayRequest(page, 7);
const reqPromise8 = waitForReplayRequest(page, 8);
const reqPromise9 = waitForReplayRequest(page, 9);

const url = await getLocalTestUrl({ testDir: __dirname });

Expand Down Expand Up @@ -127,14 +121,21 @@ sentryTest(
// -----------------------------------------------------------------------------------------
// Test subsequent link navigation to another page

const [req4] = await Promise.all([reqPromise4, page.locator('a').click()]);
// The link click is also recorded on the old page. If the old page starts to flush it before it unloads,
// that flush takes the next segment id. So we wait for the first segment of the new page.
const [req4] = await Promise.all([
waitForReplayRequest(page, event => !!event.request?.url?.includes('page-0.html')),
page.locator('a').click(),
]);

const replayEvent4 = getReplayEvent(req4);
const recording4 = getReplayRecordingContent(req4);
const page0SegmentId = replayEvent4.segment_id;

expect([4, 5]).toContain(page0SegmentId);
expect(replayEvent4).toEqual(
getExpectedReplayEvent({
segment_id: 4,
segment_id: page0SegmentId,
// @ts-expect-error this is fine
urls: [expect.stringContaining('page-0.html')],
request: {
Expand All @@ -151,14 +152,17 @@ sentryTest(
expect(normalize(recording4.fullSnapshots)).toMatchSnapshot('seg-4-snap-full');
expect(recording4.incrementalSnapshots.length).toEqual(0);

const [req5] = await Promise.all([reqPromise5, page.locator('#go-background').click()]);
const [req5] = await Promise.all([
waitForReplayRequest(page, page0SegmentId + 1),
page.locator('#go-background').click(),
]);

const replayEvent5 = getReplayEvent(req5);
const recording5 = getReplayRecordingContent(req5);

expect(replayEvent5).toEqual(
getExpectedReplayEvent({
segment_id: 5,
segment_id: page0SegmentId + 1,
urls: [],
request: {
// @ts-expect-error this is fine
Expand Down Expand Up @@ -198,14 +202,17 @@ sentryTest(
// -----------------------------------------------------------------------------------------
// Test subsequent navigation without a page reload (i.e. SPA navigation)

const [req6] = await Promise.all([reqPromise6, page.locator('#spa-navigation').click()]);
const [req6] = await Promise.all([
waitForReplayRequest(page, page0SegmentId + 2),
page.locator('#spa-navigation').click(),
]);

const replayEvent6 = getReplayEvent(req6);
const recording6 = getReplayRecordingContent(req6);

expect(replayEvent6).toEqual(
getExpectedReplayEvent({
segment_id: 6,
segment_id: page0SegmentId + 2,
urls: [`${TEST_HOST}/spa`],
request: {
url: `${TEST_HOST}/spa`,
Expand All @@ -220,14 +227,17 @@ sentryTest(
expect(recording6.fullSnapshots.length).toEqual(0);
expect(normalize(recording6.incrementalSnapshots)).toMatchSnapshot('seg-6-snap-incremental');

const [req7] = await Promise.all([reqPromise7, page.locator('#go-background').click()]);
const [req7] = await Promise.all([
waitForReplayRequest(page, page0SegmentId + 3),
page.locator('#go-background').click(),
]);

const replayEvent7 = getReplayEvent(req7);
const recording7 = getReplayRecordingContent(req7);

expect(replayEvent7).toEqual(
getExpectedReplayEvent({
segment_id: 7,
segment_id: page0SegmentId + 3,
urls: [],

request: {
Expand Down Expand Up @@ -267,14 +277,19 @@ sentryTest(
// // -----------------------------------------------------------------------------------------
// // And just to finish this off, let's go back to the index page

const [req8] = await Promise.all([reqPromise8, page.locator('a').click()]);
const [req8] = await Promise.all([
waitForReplayRequest(page, event => event.request?.url === `${TEST_HOST}/index.html`),
page.locator('a').click(),
]);

const replayEvent8 = getReplayEvent(req8);
const recording8 = getReplayRecordingContent(req8);
const indexPageSegmentId = replayEvent8.segment_id;

expect([page0SegmentId + 4, page0SegmentId + 5]).toContain(indexPageSegmentId);
expect(replayEvent8).toEqual(
getExpectedReplayEvent({
segment_id: 8,
segment_id: indexPageSegmentId,
request: {
url: `${TEST_HOST}/index.html`,
headers: {
Expand All @@ -288,14 +303,17 @@ sentryTest(
expect(normalize(recording8.fullSnapshots)).toMatchSnapshot('seg-8-snap-full');
expect(recording8.incrementalSnapshots.length).toEqual(0);

const [req9] = await Promise.all([reqPromise9, page.locator('#go-background').click()]);
const [req9] = await Promise.all([
waitForReplayRequest(page, indexPageSegmentId + 1),
page.locator('#go-background').click(),
]);

const replayEvent9 = getReplayEvent(req9);
const recording9 = getReplayRecordingContent(req9);

expect(replayEvent9).toEqual(
getExpectedReplayEvent({
segment_id: 9,
segment_id: indexPageSegmentId + 1,
urls: [],
request: {
url: `${TEST_HOST}/index.html`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ import {
import type { Route } from '@playwright/test';
import { expect } from '@playwright/test';
import { sentryTest } from '../../../../utils/fixtures';
import { envelopeRequestParser, shouldSkipTracingTest, waitForTransactionRequest } from '../../../../utils/helpers';
import {
envelopeRequestParser,
shouldSkipTracingTest,
waitForNextFrame,
waitForTransactionRequest,
} from '../../../../utils/helpers';

sentryTest(
'should capture long animation frame for top-level script.',
Expand Down Expand Up @@ -81,8 +86,11 @@ sentryTest(

await page.goto(url);

// trigger long animation frame function
await page.getByRole('button').click();
// Separate mousedown and click into different frames so LoAF reports the click handler.
await page.getByRole('button').hover();
await page.mouse.down();
await waitForNextFrame(page);
await page.mouse.up();

const eventData = envelopeRequestParser(await promise);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import type { Route } from '@playwright/test';
import { expect } from '@playwright/test';
import { sentryTest } from '../../../../utils/fixtures';
import { shouldSkipTracingTest } from '../../../../utils/helpers';
import { shouldSkipTracingTest, waitForNextFrame } from '../../../../utils/helpers';
import { collectStreamedSpans, getSpanOp, waitForStreamedSpan } from '../../../../utils/spanUtils';

sentryTest(
Expand Down Expand Up @@ -81,8 +81,11 @@ sentryTest('captures long animation frame span for event listener.', async ({ br

await page.goto(url);

// trigger long animation frame function
await page.getByRole('button').click();
// Separate mousedown and click into different frames so LoAF reports the click handler.
await page.getByRole('button').hover();
await page.mouse.down();
await waitForNextFrame(page);
await page.mouse.up();

const pageloadSpan = await pageloadSpanPromise;
await page.evaluate(() => (window as any).Sentry.flush());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ sentryTest(
await page.focus('#btn1');
await page.keyboard.press('Enter');

await page.waitForTimeout(500);
await page.waitForURL('**/sub-page-redirect');

await page.focus('#btn2');
await page.keyboard.press('Enter');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as Sentry from '@sentry/browser';

window.Sentry = Sentry;
window._testBaseTimestamp = performance.timeOrigin / 1000;
window._testInitTimestamp = (performance.timeOrigin + performance.now()) / 1000;

Sentry.init({
traceLifecycle: 'static',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ sentryTest(
const eventData = envelopeRequestParser(await pageloadEventPromise);

const traceContextData = eventData.contexts?.trace?.data;
const spanDurationSeconds = eventData.timestamp! - eventData.start_timestamp!;
const initTimestamp = await page.evaluate<number>('window._testInitTimestamp');
const secondsFromInitToSpanEnd = eventData.timestamp! - initTimestamp;

expect(traceContextData).toMatchObject({
[SENTRY_ORIGIN]: 'auto.pageload.browser',
Expand All @@ -35,9 +36,9 @@ sentryTest(
[SENTRY_IDLE_SPAN_FINISH_REASON]: 'finalTimeout',
});

// We wait for 3 seconds before calling Sentry.reportPageLoaded()
// The final timeout of 3 seconds starts at `Sentry.init()`. The span starts earlier, at the time origin.
// the margins are to account for timing weirdness in CI to avoid flakes
expect(spanDurationSeconds).toBeGreaterThan(2.5);
expect(spanDurationSeconds).toBeLessThan(3.5);
expect(secondsFromInitToSpanEnd).toBeGreaterThan(2.5);
expect(secondsFromInitToSpanEnd).toBeLessThan(3.5);
},
);
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as Sentry from '@sentry/browser';

window.Sentry = Sentry;
window._testBaseTimestamp = performance.timeOrigin / 1000;
window._testInitTimestamp = (performance.timeOrigin + performance.now()) / 1000;

Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ sentryTest(

const pageloadSpan = await pageloadSpanPromise;

const spanDurationSeconds = pageloadSpan.end_timestamp - pageloadSpan.start_timestamp;
const initTimestamp = await page.evaluate<number>('window._testInitTimestamp');
const secondsFromInitToSpanEnd = pageloadSpan.end_timestamp - initTimestamp;

expect(pageloadSpan.attributes).toMatchObject({
[SENTRY_ORIGIN]: { type: 'string', value: 'auto.pageload.browser' },
Expand All @@ -33,9 +34,9 @@ sentryTest(
[SENTRY_IDLE_SPAN_FINISH_REASON]: { type: 'string', value: 'finalTimeout' },
});

// We wait for 3 seconds before calling Sentry.reportPageLoaded()
// The final timeout of 3 seconds starts at `Sentry.init()`. The span starts earlier, at the time origin.
// the margins are to account for timing weirdness in CI to avoid flakes
expect(spanDurationSeconds).toBeGreaterThan(2.5);
expect(spanDurationSeconds).toBeLessThan(3.5);
expect(secondsFromInitToSpanEnd).toBeGreaterThan(2.5);
expect(secondsFromInitToSpanEnd).toBeLessThan(3.5);
},
);
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ btnMakeRequest.addEventListener('click', () => {
fetch('https://sentry-test-site.example/api');
});

let errorCnt = 0;
btnCaptureError.addEventListener('click', () => {
Sentry.captureException(new Error('test-error'));
// Each error has its own message, because the Dedupe integration drops an error that is equal to the previous one.
Sentry.captureException(new Error(`test-error-${++errorCnt}`));
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ sentryTest('updates the DSC when the txn name is updated and high-quality', asyn

const url = await getLocalTestUrl({ testDir: __dirname });

await page.route('http://sentry-test-site.example/**/*', route => {
await page.route('https://sentry-test-site.example/**/*', route => {
return route.fulfill({
status: 200,
contentType: 'application/json',
Expand Down Expand Up @@ -153,7 +153,7 @@ sentryTest('updates the DSC when the txn name is updated and high-quality', asyn
// 11
const requestSpanPromise = waitForStreamedSpanAndTraceHeader(
page,
span => span.name === 'GET sentry-test-site.example',
span => span.is_segment && span.name === 'GET sentry-test-site.example',
);
const baggageItemsAfterEnd = await makeRequestAndGetBaggageItems(page);
expect(baggageItemsAfterEnd).toEqual([
Expand All @@ -167,7 +167,6 @@ sentryTest('updates the DSC when the txn name is updated and high-quality', asyn
'sentry-transaction=GET%20sentry-test-site.example',
]);
const [requestSpan] = await requestSpanPromise;
expect(requestSpan.is_segment).toBe(true);
expect(requestSpan.trace_id).toBe(traceId);
expect(requestSpan).not.toHaveProperty('parent_span_id');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ sentryTest(

expect(streamSpan.parent_span_id).toBe(requestSpan.parent_span_id);
expect(streamSpan.trace_id).toBe(requestSpan.trace_id);
expect(streamSpan.end_timestamp).toBeGreaterThan(streamSpan.start_timestamp);
// The body is complete when the headers arrive, so the span can end in the same clock tick in which it starts.
expect(streamSpan.end_timestamp).toBeGreaterThanOrEqual(streamSpan.start_timestamp);
} finally {
server.close();
}
Expand Down
Loading