11import type { Page } from '@playwright/test' ;
22import { expect } from '@playwright/test' ;
3- import type { Event } from '@sentry/core' ;
43import { sentryTest } from '../../../../utils/fixtures' ;
5- import { getFirstSentryEnvelopeRequest , shouldSkipTracingTest } from '../../../../utils/helpers' ;
4+ import { shouldSkipTracingTest } from '../../../../utils/helpers' ;
5+ import { waitForStreamedSpanAndTraceHeaderOnUrl } from '../../../../utils/spanUtils' ;
6+ import { NETWORK_CONNECTION_RTT } from '@sentry/conventions/attributes' ;
67
78sentryTest . beforeEach ( ( { browserName } ) => {
89 if ( shouldSkipTracingTest ( ) || browserName !== 'chromium' ) {
@@ -22,55 +23,42 @@ async function createSessionWithLatency(page: Page, latency: number) {
2223 return session ;
2324}
2425
25- sentryTest ( 'should capture a ` connection.rtt` metric. xxx ' , async ( { getLocalTestUrl, page } ) => {
26+ sentryTest ( 'captures connection RTT without emulation ' , async ( { getLocalTestUrl, page } ) => {
2627 const url = await getLocalTestUrl ( { testDir : __dirname } ) ;
27- const eventData = await getFirstSentryEnvelopeRequest < Event > ( page , url ) ;
28+ const eventData = await waitForStreamedSpanAndTraceHeaderOnUrl ( page , url ) . then ( ( [ span ] ) => span ) ;
2829
29- expect ( eventData . measurements ) . toBeDefined ( ) ;
30- expect ( eventData . measurements ?. [ 'connection.rtt' ] ?. value ) . toBe ( 0 ) ;
30+ expect ( eventData . attributes [ NETWORK_CONNECTION_RTT ] ?. value ) . toBe ( 0 ) ;
3131} ) ;
3232
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 ) ;
33+ sentryTest ( 'captures connection RTT with emulated value 200ms on Chromium.' , async ( { getLocalTestUrl, page } ) => {
34+ const session = await createSessionWithLatency ( page , 200 ) ;
3735
38- const url = await getLocalTestUrl ( { testDir : __dirname } ) ;
39- const eventData = await getFirstSentryEnvelopeRequest < Event > ( page , url ) ;
36+ const url = await getLocalTestUrl ( { testDir : __dirname } ) ;
37+ const eventData = await waitForStreamedSpanAndTraceHeaderOnUrl ( page , url ) . then ( ( [ span ] ) => span ) ;
4038
41- await session . detach ( ) ;
39+ await session . detach ( ) ;
4240
43- expect ( eventData . measurements ) . toBeDefined ( ) ;
44- expect ( eventData . measurements ?. [ 'connection.rtt' ] ?. value ) . toBe ( 200 ) ;
45- } ,
46- ) ;
41+ expect ( eventData . attributes [ NETWORK_CONNECTION_RTT ] ?. value ) . toBe ( 200 ) ;
42+ } ) ;
4743
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 ) ;
44+ sentryTest ( 'captures connection RTT with emulated value 100ms on Chromium.' , async ( { getLocalTestUrl, page } ) => {
45+ const session = await createSessionWithLatency ( page , 100 ) ;
5246
53- const url = await getLocalTestUrl ( { testDir : __dirname } ) ;
54- const eventData = await getFirstSentryEnvelopeRequest < Event > ( page , url ) ;
47+ const url = await getLocalTestUrl ( { testDir : __dirname } ) ;
48+ const eventData = await waitForStreamedSpanAndTraceHeaderOnUrl ( page , url ) . then ( ( [ span ] ) => span ) ;
5549
56- await session . detach ( ) ;
50+ await session . detach ( ) ;
5751
58- expect ( eventData . measurements ) . toBeDefined ( ) ;
59- expect ( eventData . measurements ?. [ 'connection.rtt' ] ?. value ) . toBe ( 100 ) ;
60- } ,
61- ) ;
52+ expect ( eventData . attributes [ NETWORK_CONNECTION_RTT ] ?. value ) . toBe ( 100 ) ;
53+ } ) ;
6254
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 ) ;
55+ sentryTest ( 'captures connection RTT with emulated value 50ms on Chromium.' , async ( { getLocalTestUrl, page } ) => {
56+ const session = await createSessionWithLatency ( page , 50 ) ;
6757
68- const url = await getLocalTestUrl ( { testDir : __dirname } ) ;
69- const eventData = await getFirstSentryEnvelopeRequest < Event > ( page , url ) ;
58+ const url = await getLocalTestUrl ( { testDir : __dirname } ) ;
59+ const eventData = await waitForStreamedSpanAndTraceHeaderOnUrl ( page , url ) . then ( ( [ span ] ) => span ) ;
7060
71- await session . detach ( ) ;
61+ await session . detach ( ) ;
7262
73- expect ( eventData . measurements ) . toBeDefined ( ) ;
74- expect ( eventData . measurements ?. [ 'connection.rtt' ] ?. value ) . toBe ( 50 ) ;
75- } ,
76- ) ;
63+ expect ( eventData . attributes [ NETWORK_CONNECTION_RTT ] ?. value ) . toBe ( 50 ) ;
64+ } ) ;
0 commit comments