Skip to content

Commit 577e487

Browse files
committed
web vitals wip
1 parent 783e9bb commit 577e487

File tree

24 files changed

+894
-405
lines changed

24 files changed

+894
-405
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import * as Sentry from '@sentry/browser';
2+
3+
window.Sentry = Sentry;
4+
5+
Sentry.init({
6+
dsn: 'https://public@dsn.ingest.sentry.io/1337',
7+
integrations: [Sentry.browserTracingIntegration(), Sentry.spanStreamingIntegration()],
8+
tracesSampleRate: 1,
9+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
</head>
6+
<body>
7+
<div>Rendered</div>
8+
</body>
9+
</html>
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import type { Page } from '@playwright/test';
2+
import { expect } from '@playwright/test';
3+
import type { Event } from '@sentry/core';
4+
import { sentryTest } from '../../../../utils/fixtures';
5+
import { getFirstSentryEnvelopeRequest, shouldSkipTracingTest } from '../../../../utils/helpers';
6+
7+
sentryTest.beforeEach(({ browserName }) => {
8+
if (shouldSkipTracingTest() || browserName !== 'chromium') {
9+
sentryTest.skip();
10+
}
11+
});
12+
13+
async function createSessionWithLatency(page: Page, latency: number) {
14+
const session = await page.context().newCDPSession(page);
15+
await session.send('Network.emulateNetworkConditions', {
16+
offline: false,
17+
latency: latency,
18+
downloadThroughput: (25 * 1024) / 8,
19+
uploadThroughput: (5 * 1024) / 8,
20+
});
21+
22+
return session;
23+
}
24+
25+
sentryTest('captures a `connection.rtt` metric.', async ({ getLocalTestUrl, page }) => {
26+
const url = await getLocalTestUrl({ testDir: __dirname });
27+
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
28+
29+
expect(eventData.measurements).toBeDefined();
30+
expect(eventData.measurements?.['connection.rtt']?.value).toBe(0);
31+
});
32+
33+
sentryTest(
34+
'should capture a `connection.rtt` metric with emulated value 200ms on Chromium.',
35+
async ({ getLocalTestUrl, page }) => {
36+
const session = await createSessionWithLatency(page, 200);
37+
38+
const url = await getLocalTestUrl({ testDir: __dirname });
39+
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
40+
41+
await session.detach();
42+
43+
expect(eventData.measurements).toBeDefined();
44+
expect(eventData.measurements?.['connection.rtt']?.value).toBe(200);
45+
},
46+
);
47+
48+
sentryTest(
49+
'should capture a `connection.rtt` metric with emulated value 100ms on Chromium.',
50+
async ({ getLocalTestUrl, page }) => {
51+
const session = await createSessionWithLatency(page, 100);
52+
53+
const url = await getLocalTestUrl({ testDir: __dirname });
54+
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
55+
56+
await session.detach();
57+
58+
expect(eventData.measurements).toBeDefined();
59+
expect(eventData.measurements?.['connection.rtt']?.value).toBe(100);
60+
},
61+
);
62+
63+
sentryTest(
64+
'should capture a `connection.rtt` metric with emulated value 50ms on Chromium.',
65+
async ({ getLocalTestUrl, page }) => {
66+
const session = await createSessionWithLatency(page, 50);
67+
68+
const url = await getLocalTestUrl({ testDir: __dirname });
69+
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
70+
71+
await session.detach();
72+
73+
expect(eventData.measurements).toBeDefined();
74+
expect(eventData.measurements?.['connection.rtt']?.value).toBe(50);
75+
},
76+
);

dev-packages/browser-integration-tests/suites/tracing/metrics/web-vitals-cls-standalone-spans/init.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,8 @@ window.Sentry = Sentry;
55
Sentry.init({
66
dsn: 'https://public@dsn.ingest.sentry.io/1337',
77
integrations: [
8-
Sentry.browserTracingIntegration({
9-
idleTimeout: 9000,
10-
_experiments: {
11-
enableStandaloneClsSpans: true,
12-
},
13-
}),
8+
Sentry.browserTracingIntegration(),
9+
Sentry.spanStreamingIntegration(),
1410
],
1511
tracesSampleRate: 1,
1612
debug: true,

0 commit comments

Comments
 (0)