@@ -3,10 +3,12 @@ import { expect } from '@playwright/test';
3
3
import type { Event as SentryEvent , EventEnvelope , SpanEnvelope } from '@sentry/core' ;
4
4
import { sentryTest } from '../../../../utils/fixtures' ;
5
5
import {
6
+ envelopeRequestParser ,
6
7
getFirstSentryEnvelopeRequest ,
7
8
getMultipleSentryEnvelopeRequests ,
8
9
properFullEnvelopeRequestParser ,
9
10
shouldSkipTracingTest ,
11
+ waitForTransactionRequest ,
10
12
} from '../../../../utils/helpers' ;
11
13
12
14
sentryTest . beforeEach ( async ( { browserName, page } ) => {
@@ -31,6 +33,8 @@ sentryTest('captures LCP vital as a standalone span', async ({ getLocalTestUrl,
31
33
properFullEnvelopeRequestParser ,
32
34
) ;
33
35
36
+ const pageloadEnvelopePromise = waitForTransactionRequest ( page , e => e . contexts ?. trace ?. op === 'pageload' ) ;
37
+
34
38
page . route ( '**' , route => route . continue ( ) ) ;
35
39
page . route ( '**/my/image.png' , async ( route : Route ) => {
36
40
return route . fulfill ( {
@@ -47,10 +51,14 @@ sentryTest('captures LCP vital as a standalone span', async ({ getLocalTestUrl,
47
51
await hidePage ( page ) ;
48
52
49
53
const spanEnvelope = ( await spanEnvelopePromise ) [ 0 ] ;
54
+ const pageloadTransactionEvent = envelopeRequestParser ( await pageloadEnvelopePromise ) ;
50
55
51
56
const spanEnvelopeHeaders = spanEnvelope [ 0 ] ;
52
57
const spanEnvelopeItem = spanEnvelope [ 1 ] [ 0 ] [ 1 ] ;
53
58
59
+ const pageloadTraceId = pageloadTransactionEvent . contexts ?. trace ?. trace_id ;
60
+ expect ( pageloadTraceId ) . toMatch ( / [ a - f 0 - 9 ] { 32 } / ) ;
61
+
54
62
expect ( spanEnvelopeItem ) . toEqual ( {
55
63
data : {
56
64
'sentry.exclusive_time' : 0 ,
@@ -80,7 +88,7 @@ sentryTest('captures LCP vital as a standalone span', async ({ getLocalTestUrl,
80
88
segment_id : expect . stringMatching ( / [ a - f 0 - 9 ] { 16 } / ) ,
81
89
start_timestamp : expect . any ( Number ) ,
82
90
timestamp : spanEnvelopeItem . start_timestamp , // LCP is a point-in-time metric
83
- trace_id : expect . stringMatching ( / [ a - f 0 - 9 ] { 32 } / ) ,
91
+ trace_id : pageloadTraceId ,
84
92
} ) ;
85
93
86
94
// LCP value should be greater than 0
@@ -95,7 +103,6 @@ sentryTest('captures LCP vital as a standalone span', async ({ getLocalTestUrl,
95
103
sampled : 'true' ,
96
104
trace_id : spanEnvelopeItem . trace_id ,
97
105
sample_rand : expect . any ( String ) ,
98
- // no transaction, because span source is URL
99
106
} ,
100
107
} ) ;
101
108
} ) ;
@@ -152,10 +159,10 @@ sentryTest('sends LCP of the initial page when soft-navigating to a new page', a
152
159
153
160
const url = await getLocalTestUrl ( { testDir : __dirname } ) ;
154
161
155
- const eventData = await getFirstSentryEnvelopeRequest < SentryEvent > ( page , url ) ;
162
+ const pageloadEventData = await getFirstSentryEnvelopeRequest < SentryEvent > ( page , url ) ;
156
163
157
- expect ( eventData . type ) . toBe ( 'transaction' ) ;
158
- expect ( eventData . contexts ?. trace ?. op ) . toBe ( 'pageload' ) ;
164
+ expect ( pageloadEventData . type ) . toBe ( 'transaction' ) ;
165
+ expect ( pageloadEventData . contexts ?. trace ?. op ) . toBe ( 'pageload' ) ;
159
166
160
167
const spanEnvelopePromise = getMultipleSentryEnvelopeRequests < SpanEnvelope > (
161
168
page ,
@@ -173,7 +180,8 @@ sentryTest('sends LCP of the initial page when soft-navigating to a new page', a
173
180
const spanEnvelopeItem = spanEnvelope [ 1 ] [ 0 ] [ 1 ] ;
174
181
175
182
expect ( spanEnvelopeItem . measurements ?. lcp ?. value ) . toBeGreaterThan ( 0 ) ;
176
- expect ( spanEnvelopeItem . data ?. [ 'sentry.pageload.span_id' ] ) . toMatch ( / [ a - f 0 - 9 ] { 16 } / ) ;
183
+ expect ( spanEnvelopeItem . data ?. [ 'sentry.pageload.span_id' ] ) . toBe ( pageloadEventData . contexts ?. trace ?. span_id ) ;
184
+ expect ( spanEnvelopeItem . trace_id ) . toBe ( pageloadEventData . contexts ?. trace ?. trace_id ) ;
177
185
} ) ;
178
186
179
187
sentryTest ( "doesn't send further LCP after the first navigation" , async ( { getLocalTestUrl, page } ) => {
0 commit comments