Skip to content

Commit 894c8d8

Browse files
authored
chore: use performance directly in xhr plugin (#1651)
1 parent 25a2f65 commit 894c8d8

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

packages/opentelemetry-instrumentation-xml-http-request/src/xhr.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,9 @@ export class XMLHttpRequestInstrumentation extends InstrumentationBase<
230230
// fallback - either Observer is not available or it took longer
231231
// then OBSERVER_WAIT_TIME_MS and observer didn't collect enough
232232
// information
233-
resources = otperformance.getEntriesByType(
234-
// ts thinks this is the perf_hooks module, but it is the browser performance api
235-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
236-
'resource' as any
233+
// ts thinks this is the perf_hooks module, but it is the browser performance api
234+
resources = ((otperformance as unknown) as Performance).getEntriesByType(
235+
'resource'
237236
) as PerformanceResourceTiming[];
238237
}
239238

packages/opentelemetry-instrumentation-xml-http-request/test/xhr.test.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,10 @@ describe('xhr', () => {
189189
})
190190
);
191191

192-
spyEntries = sandbox.stub(performance, 'getEntriesByType');
192+
spyEntries = sandbox.stub(
193+
(performance as unknown) as Performance,
194+
'getEntriesByType'
195+
);
193196
spyEntries.withArgs('resource').returns(resources);
194197
xmlHttpRequestInstrumentation = new XMLHttpRequestInstrumentation(
195198
config
@@ -709,7 +712,10 @@ describe('xhr', () => {
709712
})
710713
);
711714

712-
spyEntries = sandbox.stub(performance, 'getEntriesByType');
715+
spyEntries = sandbox.stub(
716+
(performance as unknown) as Performance,
717+
'getEntriesByType'
718+
);
713719
spyEntries.withArgs('resource').returns(resources);
714720

715721
webTracerWithZoneProvider = new WebTracerProvider({

0 commit comments

Comments
 (0)