@@ -54,13 +54,13 @@ export function startResourceCollection(
54
54
} ) . subscribe ( ( entries ) => {
55
55
for ( const entry of entries ) {
56
56
if ( ! isResourceEntryRequestType ( entry ) ) {
57
- handleResource ( ( ) => processResourceEntry ( entry , configuration ) )
57
+ handleResource ( ( ) => processResourceEntry ( entry , configuration , pageStateHistory ) )
58
58
}
59
59
}
60
60
} )
61
61
62
62
retrieveInitialDocumentResourceTimingImpl ( configuration , ( timing ) => {
63
- handleResource ( ( ) => processResourceEntry ( timing , configuration ) )
63
+ handleResource ( ( ) => processResourceEntry ( timing , configuration , pageStateHistory ) )
64
64
} )
65
65
66
66
function handleResource ( computeRawEvent : ( ) => RawRumEventCollectedData < RawRumResourceEvent > | undefined ) {
@@ -91,11 +91,15 @@ function processRequest(
91
91
return
92
92
}
93
93
94
+ const duration = computeRequestDuration ( pageStateHistory , startClocks , request . duration )
95
+
94
96
const type = request . type === RequestType . XHR ? ResourceType . XHR : ResourceType . FETCH
95
97
96
- const correspondingTimingOverrides = matchingTiming ? computeResourceEntryMetrics ( matchingTiming ) : undefined
98
+ console . log ( ' matchingTiming' , matchingTiming )
97
99
98
- const duration = computeRequestDuration ( pageStateHistory , startClocks , request . duration )
100
+ const correspondingTimingOverrides = matchingTiming
101
+ ? computeResourceEntryMetrics ( matchingTiming , pageStateHistory )
102
+ : undefined
99
103
100
104
const resourceEvent = combine (
101
105
{
@@ -137,7 +141,8 @@ function processRequest(
137
141
138
142
function processResourceEntry (
139
143
entry : RumPerformanceResourceTiming ,
140
- configuration : RumConfiguration
144
+ configuration : RumConfiguration ,
145
+ pageStateHistory : PageStateHistory
141
146
) : RawRumEventCollectedData < RawRumResourceEvent > | undefined {
142
147
const startClocks = relativeToClocks ( entry . startTime )
143
148
const tracingInfo = computeResourceEntryTracingInfo ( entry , configuration )
@@ -146,7 +151,7 @@ function processResourceEntry(
146
151
}
147
152
148
153
const type = computeResourceEntryType ( entry )
149
- const entryMetrics = computeResourceEntryMetrics ( entry )
154
+ const entryMetrics = computeResourceEntryMetrics ( entry , pageStateHistory )
150
155
151
156
const resourceEvent = combine (
152
157
{
@@ -176,14 +181,23 @@ function processResourceEntry(
176
181
}
177
182
}
178
183
179
- function computeResourceEntryMetrics ( entry : RumPerformanceResourceTiming ) {
184
+ function computeResourceEntryMetrics ( entry : RumPerformanceResourceTiming , pageStateHistory : PageStateHistory ) {
180
185
const { renderBlockingStatus } = entry
186
+ if ( ! pageStateHistory . wasInPageStateDuringPeriod ( PageState . FROZEN , entry . startTime , entry . duration ) ) {
187
+ return {
188
+ resource : {
189
+ duration : computeResourceEntryDuration ( entry ) ,
190
+ render_blocking_status : renderBlockingStatus ,
191
+ ...computeResourceEntrySize ( entry ) ,
192
+ ...computeResourceEntryDetails ( entry ) ,
193
+ } ,
194
+ }
195
+ }
196
+
181
197
return {
182
198
resource : {
183
- duration : computeResourceEntryDuration ( entry ) ,
184
199
render_blocking_status : renderBlockingStatus ,
185
200
...computeResourceEntrySize ( entry ) ,
186
- ...computeResourceEntryDetails ( entry ) ,
187
201
} ,
188
202
}
189
203
}
@@ -216,16 +230,16 @@ function computeResourceEntryTracingInfo(entry: RumPerformanceResourceTiming, co
216
230
}
217
231
}
218
232
219
- function computeRequestDuration ( pageStateHistory : PageStateHistory , startClocks : ClocksState , duration : Duration ) {
220
- return ! pageStateHistory . wasInPageStateDuringPeriod ( PageState . FROZEN , startClocks . relative , duration )
221
- ? toServerDuration ( duration )
222
- : undefined
223
- }
224
-
225
233
/**
226
234
* The status is 0 for cross-origin resources without CORS headers, so the status is meaningless, and we shouldn't report it
227
235
* https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming/responseStatus#cross-origin_response_status_codes
228
236
*/
229
237
function discardZeroStatus ( statusCode : number | undefined ) : number | undefined {
230
238
return statusCode === 0 ? undefined : statusCode
231
239
}
240
+
241
+ function computeRequestDuration ( pageStateHistory : PageStateHistory , startClocks : ClocksState , duration : Duration ) {
242
+ return ! pageStateHistory . wasInPageStateDuringPeriod ( PageState . FROZEN , startClocks . relative , duration )
243
+ ? toServerDuration ( duration )
244
+ : undefined
245
+ }
0 commit comments