@@ -166,6 +166,15 @@ export function instrumentOutgoingRequests(_options?: Partial<RequestInstrumenta
166
166
}
167
167
}
168
168
169
+ function isPerformanceResourceTiming ( entry : PerformanceEntry ) : entry is PerformanceResourceTiming {
170
+ return (
171
+ entry . entryType === 'resource' &&
172
+ 'initiatorType' in entry &&
173
+ 'nextHopProtocol' in entry &&
174
+ ( entry . initiatorType === 'fetch' || entry . initiatorType === 'xmlhttprequest' )
175
+ ) ;
176
+ }
177
+
169
178
/**
170
179
* Creates a temporary observer to listen to the next fetch/xhr resourcing timings,
171
180
* so that when timings hit their per-browser limit they don't need to be removed.
@@ -175,9 +184,9 @@ export function instrumentOutgoingRequests(_options?: Partial<RequestInstrumenta
175
184
function addHTTPTimings ( span : Span ) : void {
176
185
const url = span . data . url ;
177
186
const observer = new PerformanceObserver ( list => {
178
- const entries = list . getEntries ( ) as PerformanceResourceTiming [ ] ;
187
+ const entries = list . getEntries ( ) ;
179
188
entries . forEach ( entry => {
180
- if ( ( entry . initiatorType === 'fetch' || entry . initiatorType === 'xmlhttprequest' ) && entry . name . endsWith ( url ) ) {
189
+ if ( isPerformanceResourceTiming ( entry ) && entry . name . endsWith ( url ) ) {
181
190
const spanData = resourceTimingEntryToSpanData ( entry ) ;
182
191
spanData . forEach ( data => span . setData ( ...data ) ) ;
183
192
observer . disconnect ( ) ;
@@ -220,7 +229,7 @@ export function extractNetworkProtocol(nextHopProtocol: string): { name: string;
220
229
return { name, version } ;
221
230
}
222
231
223
- function getAbsoluteTime ( time : number ) : number {
232
+ function getAbsoluteTime ( time : number = 0 ) : number {
224
233
return ( ( browserPerformanceTimeOrigin || performance . timeOrigin ) + time ) / 1000 ;
225
234
}
226
235
0 commit comments