From 4ddaa76a687d19631c313d903c4e3a883bc57980 Mon Sep 17 00:00:00 2001 From: k-fish Date: Mon, 17 Jul 2023 11:42:51 -0400 Subject: [PATCH] Normalize timings --- .../tracing-internal/src/browser/request.ts | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/packages/tracing-internal/src/browser/request.ts b/packages/tracing-internal/src/browser/request.ts index 28efe77d4b99..3407c33a8f2a 100644 --- a/packages/tracing-internal/src/browser/request.ts +++ b/packages/tracing-internal/src/browser/request.ts @@ -182,6 +182,10 @@ function addHTTPTimings(span: Span): void { }); } +function getAbsoluteTime(time: number): number { + return ((browserPerformanceTimeOrigin || performance.timeOrigin) + time) / 1000; +} + function resourceTimingEntryToSpanData(resourceTiming: PerformanceResourceTiming): [string, string | number][] { const version = resourceTiming.nextHopProtocol.split('/')[1] || 'none'; @@ -195,16 +199,16 @@ function resourceTimingEntryToSpanData(resourceTiming: PerformanceResourceTiming } return [ ...timingSpanData, - ['http.request.redirect_start', resourceTiming.redirectStart], - ['http.request.fetch_start', resourceTiming.fetchStart], - ['http.request.domain_lookup_start', resourceTiming.domainLookupStart], - ['http.request.domain_lookup_end', resourceTiming.domainLookupEnd], - ['http.request.connect_start', resourceTiming.connectStart], - ['http.request.secure_connection_start', resourceTiming.secureConnectionStart], - ['http.request.connection_end', resourceTiming.connectEnd], - ['http.request.request_start', resourceTiming.requestStart], - ['http.request.response_start', resourceTiming.responseStart], - ['http.request.response_end', resourceTiming.responseEnd], + ['http.request.redirect_start', getAbsoluteTime(resourceTiming.redirectStart)], + ['http.request.fetch_start', getAbsoluteTime(resourceTiming.fetchStart)], + ['http.request.domain_lookup_start', getAbsoluteTime(resourceTiming.domainLookupStart)], + ['http.request.domain_lookup_end', getAbsoluteTime(resourceTiming.domainLookupEnd)], + ['http.request.connect_start', getAbsoluteTime(resourceTiming.connectStart)], + ['http.request.secure_connection_start', getAbsoluteTime(resourceTiming.secureConnectionStart)], + ['http.request.connection_end', getAbsoluteTime(resourceTiming.connectEnd)], + ['http.request.request_start', getAbsoluteTime(resourceTiming.requestStart)], + ['http.request.response_start', getAbsoluteTime(resourceTiming.responseStart)], + ['http.request.response_end', getAbsoluteTime(resourceTiming.responseEnd)], ]; }