@@ -2,7 +2,6 @@ import type { Client, HandlerDataXhr, SentryWrappedXMLHttpRequest, Span, WebFetc
22import {
33 addFetchEndInstrumentationHandler ,
44 addFetchInstrumentationHandler ,
5- browserPerformanceTimeOrigin ,
65 getActiveSpan ,
76 getClient ,
87 getLocationHref ,
@@ -23,10 +22,10 @@ import type { XhrHint } from '@sentry-internal/browser-utils';
2322import {
2423 addPerformanceInstrumentationHandler ,
2524 addXhrInstrumentationHandler ,
26- extractNetworkProtocol ,
2725 SENTRY_XHR_DATA_KEY ,
2826} from '@sentry-internal/browser-utils' ;
2927import { WINDOW } from '../helpers' ;
28+ import { resourceTimingToSpanAttributes } from './resource-timing' ;
3029
3130/** Options for Request Instrumentation */
3231export interface RequestInstrumentationOptions {
@@ -238,8 +237,8 @@ function addHTTPTimings(span: Span): void {
238237 const cleanup = addPerformanceInstrumentationHandler ( 'resource' , ( { entries } ) => {
239238 entries . forEach ( entry => {
240239 if ( isPerformanceResourceTiming ( entry ) && entry . name . endsWith ( url ) ) {
241- const spanData = resourceTimingEntryToSpanData ( entry ) ;
242- spanData . forEach ( data => span . setAttribute ( ...data ) ) ;
240+ const spanAttributes = resourceTimingToSpanAttributes ( entry ) ;
241+ spanAttributes . forEach ( attributeArray => span . setAttribute ( ...attributeArray ) ) ;
243242 // In the next tick, clean this handler up
244243 // We have to wait here because otherwise this cleans itself up before it is fully done
245244 setTimeout ( cleanup ) ;
@@ -248,35 +247,6 @@ function addHTTPTimings(span: Span): void {
248247 } ) ;
249248}
250249
251- function getAbsoluteTime ( time : number = 0 ) : number {
252- return ( ( browserPerformanceTimeOrigin ( ) || performance . timeOrigin ) + time ) / 1000 ;
253- }
254-
255- function resourceTimingEntryToSpanData ( resourceTiming : PerformanceResourceTiming ) : [ string , string | number ] [ ] {
256- const { name, version } = extractNetworkProtocol ( resourceTiming . nextHopProtocol ) ;
257-
258- const timingSpanData : [ string , string | number ] [ ] = [ ] ;
259-
260- timingSpanData . push ( [ 'network.protocol.version' , version ] , [ 'network.protocol.name' , name ] ) ;
261-
262- if ( ! browserPerformanceTimeOrigin ( ) ) {
263- return timingSpanData ;
264- }
265- return [
266- ...timingSpanData ,
267- [ 'http.request.redirect_start' , getAbsoluteTime ( resourceTiming . redirectStart ) ] ,
268- [ 'http.request.fetch_start' , getAbsoluteTime ( resourceTiming . fetchStart ) ] ,
269- [ 'http.request.domain_lookup_start' , getAbsoluteTime ( resourceTiming . domainLookupStart ) ] ,
270- [ 'http.request.domain_lookup_end' , getAbsoluteTime ( resourceTiming . domainLookupEnd ) ] ,
271- [ 'http.request.connect_start' , getAbsoluteTime ( resourceTiming . connectStart ) ] ,
272- [ 'http.request.secure_connection_start' , getAbsoluteTime ( resourceTiming . secureConnectionStart ) ] ,
273- [ 'http.request.connection_end' , getAbsoluteTime ( resourceTiming . connectEnd ) ] ,
274- [ 'http.request.request_start' , getAbsoluteTime ( resourceTiming . requestStart ) ] ,
275- [ 'http.request.response_start' , getAbsoluteTime ( resourceTiming . responseStart ) ] ,
276- [ 'http.request.response_end' , getAbsoluteTime ( resourceTiming . responseEnd ) ] ,
277- ] ;
278- }
279-
280250/**
281251 * A function that determines whether to attach tracing headers to a request.
282252 * We only export this function for testing purposes.
0 commit comments