Skip to content

Commit f3589b4

Browse files
authored
revert: web vitals 4.x upgrade, reportAllLCP, and reportAllCLS (#633)
1 parent 26aad1c commit f3589b4

File tree

8 files changed

+23
-46
lines changed

8 files changed

+23
-46
lines changed

docs/configuration.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,6 @@ const awsRum: AwsRum = new AwsRum(
188188
| --- | --- | --- | --- |
189189
| eventLimit | Number | `10` | The maximum number of resources to record load timing. <br/><br/>There may be many similar resources on a page (e.g., images) and recording all resources may add expense without adding value. The web client records all HTML files and JavaScript files, while recording a sample of stylesheets, images and fonts. Increasing the event limit increases the maximum number of sampled resources. |
190190
| ignore | Function(event: PerformanceEntry) : any | `(entry: PerformanceEntry) => entry.entryType === 'resource' && !/^https?:/.test(entry.name)` | A function which accepts a [PerformanceEntry](https://developer.mozilla.org/en-US/docs/Web/API/PerformanceEntry) and returns a value that coerces to true when the PerformanceEntry should be ignored.</br></br> By default, [PerformanceResourceTiming](https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming) entries with URLs that do not have http(s) schemes are ignored. This causes resources loaded by browser extensions to be ignored. |
191-
| recordAllTypes | String[] | ['document', 'script', 'stylesheet', 'font'] | A list of resource types that are always recorded, no matter if the resource event limit has been reached. Possible values are 'other', 'stylesheet', 'document', 'script', 'image', and 'font'. |
192-
| sampleTypes | String[] | ['image', 'other'] | A list of resource types that are only recorded if the resource event limit has not been reached. Possible values are 'other', 'stylesheet', 'document', 'script', 'image', and 'font'. |
193-
| reportAllLCP | boolean | FALSE | If true, then all increases to LCP are recorded. |
194-
| reportAllCLS | boolean | FALSE | If true, then all increases to CLS are recorded. |
195191

196192
For example, the following telemetry config array causes the web client to ignore all resource entries.
197193

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
"shimmer": "^1.2.1",
126126
"ua-parser-js": "^1.0.33",
127127
"uuid": "^9.0.0",
128-
"web-vitals": "^4.0.0"
128+
"web-vitals": "^3.0.2"
129129
},
130130
"lint-staged": {
131131
"*.ts": "npm run lint:errors",

src/loader/loader-web-vital-event.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ loader('cwr', 'abc123', '1.0', 'us-west-2', './rum_javascript_telemetry.js', {
99
eventPluginsToLoad: [
1010
new ResourcePlugin(),
1111
new NavigationPlugin(),
12-
new WebVitalsPlugin({
13-
reportAllCLS: true
14-
})
12+
new WebVitalsPlugin()
1513
],
1614
telemetries: [],
1715
clientBuilder: showRequestClientBuilder

src/orchestration/Orchestration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ export class Orchestration {
493493
return [
494494
new NavigationPlugin(config),
495495
new ResourcePlugin(config),
496-
new WebVitalsPlugin(config)
496+
new WebVitalsPlugin()
497497
];
498498
},
499499
[TelemetryEnum.Interaction]: (config: object): InternalPlugin[] => {

src/plugins/event-plugins/WebVitalsPlugin.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,12 @@ import {
2828
RumLCPAttribution,
2929
isLCPSupported
3030
} from '../../utils/common-utils';
31-
import {
32-
defaultPerformancePluginConfig,
33-
PerformancePluginConfig
34-
} from '../../plugins/utils/performance-utils';
3531

3632
export const WEB_VITAL_EVENT_PLUGIN_ID = 'web-vitals';
3733

3834
export class WebVitalsPlugin extends InternalPlugin {
39-
private config: PerformancePluginConfig;
40-
constructor(config?: Partial<PerformancePluginConfig>) {
35+
constructor() {
4136
super(WEB_VITAL_EVENT_PLUGIN_ID);
42-
this.config = { ...defaultPerformancePluginConfig, ...config };
4337
}
4438
private resourceEventIds = new Map<string, string>();
4539
private navigationEventId?: string;
@@ -51,15 +45,14 @@ export class WebVitalsPlugin extends InternalPlugin {
5145
// eslint-disable-next-line @typescript-eslint/no-empty-function
5246
disable(): void {}
5347

48+
// eslint-disable-next-line @typescript-eslint/no-empty-function
49+
configure(config: any): void {}
50+
5451
protected onload(): void {
5552
this.context.eventBus.subscribe(Topic.EVENT, this.handleEvent); // eslint-disable-line @typescript-eslint/unbound-method
56-
onLCP((metric) => this.handleLCP(metric), {
57-
reportAllChanges: this.config.reportAllLCP
58-
});
53+
onLCP((metric) => this.handleLCP(metric));
5954
onFID((metric) => this.handleFID(metric));
60-
onCLS((metric) => this.handleCLS(metric), {
61-
reportAllChanges: this.config.reportAllCLS
62-
});
55+
onCLS((metric) => this.handleCLS(metric));
6356
}
6457

6558
private handleEvent = (event: ParsedRumEvent) => {
@@ -90,7 +83,7 @@ export class WebVitalsPlugin extends InternalPlugin {
9083
url: a.url,
9184
timeToFirstByte: a.timeToFirstByte,
9285
resourceLoadDelay: a.resourceLoadDelay,
93-
resourceLoadTime: a.resourceLoadDuration,
86+
resourceLoadTime: a.resourceLoadTime,
9487
elementRenderDelay: a.elementRenderDelay
9588
};
9689
if (a.lcpResourceEntry) {

src/plugins/event-plugins/__tests__/WebVitalsPlugin.test.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@ import { context, record } from '../../../test-utils/test-utils';
1818
import { Topic } from '../../../event-bus/EventBus';
1919
import { WebVitalsPlugin } from '../WebVitalsPlugin';
2020
import { navigationEvent } from '../../../test-utils/mock-data';
21-
import {
22-
CLSMetricWithAttribution,
23-
FIDMetricWithAttribution,
24-
LCPMetricWithAttribution
25-
} from 'web-vitals';
2621

2722
const mockLCPData = {
2823
delta: 239.51,
@@ -34,10 +29,10 @@ const mockLCPData = {
3429
url: 'example.com/source.png',
3530
timeToFirstByte: 1000,
3631
resourceLoadDelay: 250,
37-
resourceLoadDuration: 1000,
32+
resourceLoadTime: 1000,
3833
elementRenderDelay: 250
3934
}
40-
} as LCPMetricWithAttribution;
35+
};
4136

4237
const mockFIDData = {
4338
delta: 1.2799999676644802,
@@ -50,7 +45,7 @@ const mockFIDData = {
5045
eventType: 'keydown',
5146
loadState: 'dom-interactive'
5247
}
53-
} as FIDMetricWithAttribution;
48+
};
5449

5550
const mockCLSData = {
5651
delta: 0,
@@ -63,7 +58,7 @@ const mockCLSData = {
6358
largestShiftTime: 3447485.600000024,
6459
loadState: 'dom-interactive'
6560
}
66-
} as CLSMetricWithAttribution;
61+
};
6762

6863
// only need hasLatency fields
6964
const imagePerformanceEntry = {
@@ -133,8 +128,7 @@ describe('WebVitalsPlugin tests', () => {
133128
timeToFirstByte: mockLCPData.attribution.timeToFirstByte,
134129
resourceLoadDelay:
135130
mockLCPData.attribution.resourceLoadDelay,
136-
resourceLoadTime:
137-
mockLCPData.attribution.resourceLoadDuration,
131+
resourceLoadTime: mockLCPData.attribution.resourceLoadTime,
138132
elementRenderDelay:
139133
mockLCPData.attribution.elementRenderDelay
140134
})

src/plugins/utils/performance-utils.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ export type PerformancePluginConfig = {
1212
ignore: (event: PerformanceEntry) => any;
1313
recordAllTypes: ResourceType[];
1414
sampleTypes: ResourceType[];
15-
reportAllLCP: boolean;
16-
reportAllCLS: boolean;
1715
};
1816

1917
export const defaultPerformancePluginConfig = {
@@ -25,7 +23,5 @@ export const defaultPerformancePluginConfig = {
2523
ResourceType.STYLESHEET,
2624
ResourceType.FONT
2725
],
28-
sampleTypes: [ResourceType.IMAGE, ResourceType.OTHER],
29-
reportAllLCP: false,
30-
reportAllCLS: false
26+
sampleTypes: [ResourceType.IMAGE, ResourceType.OTHER]
3127
};

0 commit comments

Comments
 (0)