Skip to content

Commit

Permalink
add logic to record performance for all API calls
Browse files Browse the repository at this point in the history
  • Loading branch information
samholton committed Jun 2, 2022
1 parent 75dee61 commit 319161b
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/plugins/event-plugins/ResourcePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,20 @@ export class ResourcePlugin extends InternalPlugin {
// Out of n resource events, x events are recorded using Observer API
const type: ResourceType = getResourceFileType(event.name);
if (this.config.recordAllTypes.includes(type)) {
recordAll.push(event);
// record ALL fetch/xmlhttprequest requests ignoring this.config.eventLimit
// requires ResourceType.OTHER to be added to this.config.recordAllTypes
// added because observer was capturing events but record event blocks only ran on page load
// probably a better way to do this, but quick fix for our use case to capture API calls
const prt: PerformanceResourceTiming = event as PerformanceResourceTiming;
if (
['fetch', 'xmlhttprequest'].includes(
prt.initiatorType
)
) {
this.recordResourceEvent(prt);
} else {
recordAll.push(event);
}
} else if (this.config.sampleTypes.includes(type)) {
sample.push(event);
}
Expand All @@ -93,7 +106,18 @@ export class ResourcePlugin extends InternalPlugin {
events.forEach((event) => {
const type: ResourceType = getResourceFileType(event.name);
if (this.config.recordAllTypes.includes(type)) {
recordAll.push(event);
// record ALL fetch/xmlhttprequest requests ignoring this.config.eventLimit
// requires ResourceType.OTHER to be added to this.config.recordAllTypes
// added because observer was capturing events but record event blocks only ran on page load
// probably a better way to do this, but quick fix for our use case to capture API calls
const prt: PerformanceResourceTiming = event as PerformanceResourceTiming;
if (
['fetch', 'xmlhttprequest'].includes(prt.initiatorType)
) {
this.recordResourceEvent(prt);
} else {
recordAll.push(event);
}
} else if (this.config.sampleTypes.includes(type)) {
sample.push(event);
}
Expand Down

0 comments on commit 319161b

Please sign in to comment.