Skip to content

Commit f1ebe53

Browse files
committed
feat: add config options for reportAll CLS and LCP
1 parent 8ee8e56 commit f1ebe53

File tree

5 files changed

+26
-9
lines changed

5 files changed

+26
-9
lines changed

docs/configuration.md

+4
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,10 @@ 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. |
191195

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

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

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

src/orchestration/Orchestration.ts

+1-1
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()
496+
new WebVitalsPlugin(config)
497497
];
498498
},
499499
[TelemetryEnum.Interaction]: (config: object): InternalPlugin[] => {

src/plugins/event-plugins/WebVitalsPlugin.ts

+13-6
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,18 @@ import {
2828
RumLCPAttribution,
2929
isLCPSupported
3030
} from '../../utils/common-utils';
31+
import {
32+
defaultPerformancePluginConfig,
33+
PerformancePluginConfig
34+
} from '../../plugins/utils/performance-utils';
3135

3236
export const WEB_VITAL_EVENT_PLUGIN_ID = 'web-vitals';
3337

3438
export class WebVitalsPlugin extends InternalPlugin {
35-
constructor() {
39+
private config: PerformancePluginConfig;
40+
constructor(config?: Partial<PerformancePluginConfig>) {
3641
super(WEB_VITAL_EVENT_PLUGIN_ID);
42+
this.config = { ...defaultPerformancePluginConfig, ...config };
3743
}
3844
private resourceEventIds = new Map<string, string>();
3945
private navigationEventId?: string;
@@ -45,14 +51,15 @@ export class WebVitalsPlugin extends InternalPlugin {
4551
// eslint-disable-next-line @typescript-eslint/no-empty-function
4652
disable(): void {}
4753

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

5865
private handleEvent = (event: ParsedRumEvent) => {

src/plugins/utils/performance-utils.ts

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

1719
export const defaultPerformancePluginConfig = {
@@ -23,5 +25,7 @@ export const defaultPerformancePluginConfig = {
2325
ResourceType.STYLESHEET,
2426
ResourceType.FONT
2527
],
26-
sampleTypes: [ResourceType.IMAGE, ResourceType.OTHER]
28+
sampleTypes: [ResourceType.IMAGE, ResourceType.OTHER],
29+
reportAllLCP: false,
30+
reportAllCLS: false
2731
};

0 commit comments

Comments
 (0)