File tree 2 files changed +25
-6
lines changed
opentelemetry-instrumentation-fetch/src
2 files changed +25
-6
lines changed Original file line number Diff line number Diff line change @@ -32,7 +32,17 @@ import { VERSION } from './version';
32
32
// hard to say how long it should really wait, seems like 300ms is
33
33
// safe enough
34
34
const OBSERVER_WAIT_TIME_MS = 300 ;
35
- const urlNormalizingA = document . createElement ( 'a' ) ;
35
+
36
+ // Used to normalize relative URLs
37
+ let a : HTMLAnchorElement | undefined ;
38
+ const getUrlNormalizingAnchor = ( ) => {
39
+ if ( ! a ) {
40
+ a = document . createElement ( 'a' ) ;
41
+ }
42
+
43
+ return a ;
44
+ } ;
45
+
36
46
/**
37
47
* FetchPlugin Config
38
48
*/
@@ -359,11 +369,12 @@ export class FetchInstrumentation extends InstrumentationBase<
359
369
360
370
const observer : PerformanceObserver = new PerformanceObserver ( list => {
361
371
const perfObsEntries = list . getEntries ( ) as PerformanceResourceTiming [ ] ;
362
- urlNormalizingA . href = spanUrl ;
372
+ const urlNormalizingAnchor = getUrlNormalizingAnchor ( ) ;
373
+ urlNormalizingAnchor . href = spanUrl ;
363
374
perfObsEntries . forEach ( entry => {
364
375
if (
365
376
entry . initiatorType === 'fetch' &&
366
- entry . name === urlNormalizingA . href
377
+ entry . name === urlNormalizingAnchor . href
367
378
) {
368
379
entries . push ( entry ) ;
369
380
}
Original file line number Diff line number Diff line change @@ -29,7 +29,14 @@ import {
29
29
import { HttpAttribute } from '@opentelemetry/semantic-conventions' ;
30
30
31
31
// Used to normalize relative URLs
32
- const urlNormalizingA = document . createElement ( 'a' ) ;
32
+ let a : HTMLAnchorElement | undefined ;
33
+ const getUrlNormalizingAnchor = ( ) => {
34
+ if ( ! a ) {
35
+ a = document . createElement ( 'a' ) ;
36
+ }
37
+
38
+ return a ;
39
+ } ;
33
40
34
41
/**
35
42
* Helper function to be able to use enum as typed key in type and in interface when using forEach
@@ -125,8 +132,9 @@ export function getResource(
125
132
initiatorType ?: string
126
133
) : PerformanceResourceTimingInfo {
127
134
// de-relativize the URL before usage (does no harm to absolute URLs)
128
- urlNormalizingA . href = spanUrl ;
129
- spanUrl = urlNormalizingA . href ;
135
+ const urlNormalizingAnchor = getUrlNormalizingAnchor ( ) ;
136
+ urlNormalizingAnchor . href = spanUrl ;
137
+ spanUrl = urlNormalizingAnchor . href ;
130
138
131
139
const filteredResources = filterResourcesForSpan (
132
140
spanUrl ,
You can’t perform that action at this time.
0 commit comments