@@ -2,7 +2,6 @@ import type { Client, HandlerDataXhr, SentryWrappedXMLHttpRequest, Span, WebFetc
2
2
import {
3
3
addFetchEndInstrumentationHandler ,
4
4
addFetchInstrumentationHandler ,
5
- browserPerformanceTimeOrigin ,
6
5
getActiveSpan ,
7
6
getClient ,
8
7
getLocationHref ,
@@ -23,10 +22,10 @@ import type { XhrHint } from '@sentry-internal/browser-utils';
23
22
import {
24
23
addPerformanceInstrumentationHandler ,
25
24
addXhrInstrumentationHandler ,
26
- extractNetworkProtocol ,
27
25
SENTRY_XHR_DATA_KEY ,
28
26
} from '@sentry-internal/browser-utils' ;
29
27
import { WINDOW } from '../helpers' ;
28
+ import { resourceTimingToSpanAttributes } from './resource-timing' ;
30
29
31
30
/** Options for Request Instrumentation */
32
31
export interface RequestInstrumentationOptions {
@@ -238,8 +237,8 @@ function addHTTPTimings(span: Span): void {
238
237
const cleanup = addPerformanceInstrumentationHandler ( 'resource' , ( { entries } ) => {
239
238
entries . forEach ( entry => {
240
239
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 ) ) ;
243
242
// In the next tick, clean this handler up
244
243
// We have to wait here because otherwise this cleans itself up before it is fully done
245
244
setTimeout ( cleanup ) ;
@@ -248,35 +247,6 @@ function addHTTPTimings(span: Span): void {
248
247
} ) ;
249
248
}
250
249
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
-
280
250
/**
281
251
* A function that determines whether to attach tracing headers to a request.
282
252
* We only export this function for testing purposes.
0 commit comments