Skip to content

Commit 41347d3

Browse files
authored
feat: record INP (#620)
1 parent 8d8cf2f commit 41347d3

26 files changed

+1172
-614
lines changed

docs/configuration.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,11 @@ const awsRum: AwsRum = new AwsRum(
189189
| --- | --- | --- | --- |
190190
| 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. |
191191
| 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. |
192+
| 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'. |
193+
| 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'. |
194+
| reportAllLCP | Boolean | `false` | If true, then all increases to LCP are recorded. |
195+
| reportAllCLS | Boolean | `false` | If true, then all increases to CLS are recorded. |
196+
| reportAllINP | boolean | `false` | If true, then all increases to INP are recorded. |
192197

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

@@ -197,12 +202,14 @@ telemetries: [
197202
[
198203
'errors',
199204
'http',
200-
'performance',
201-
{
202-
ignore: (entry: PerformanceEntry) => {
203-
return entry.entryType === 'resource';
205+
[
206+
'performance',
207+
{
208+
ignore: (entry: PerformanceEntry) => {
209+
return entry.entryType === 'resource';
210+
}
204211
}
205-
}
212+
]
206213
]
207214
];
208215
```

package-lock.json

Lines changed: 4 additions & 4 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": "^3.0.2"
128+
"web-vitals": "^4.0.0"
129129
},
130130
"lint-staged": {
131131
"*.ts": "npm run lint:errors",

src/__integ__/cookiesDisabled.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { SESSION_START_EVENT_TYPE } from '../sessions/SessionManager';
1+
import { SESSION_START_EVENT_TYPE } from '../plugins/utils/constant';
22
import { Selector } from 'testcafe';
33
import { REQUEST_BODY } from '../test-utils/integ-test-utils';
44

src/__integ__/cookiesEnabled.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { SESSION_START_EVENT_TYPE } from '../sessions/SessionManager';
1+
import { SESSION_START_EVENT_TYPE } from '../plugins/utils/constant';
22
import { Selector } from 'testcafe';
33
import { REQUEST_BODY } from '../test-utils/integ-test-utils';
44

src/dispatch/Dispatch.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,15 +161,15 @@ export class Dispatch {
161161

162162
private flushSync: EventListener = () => {
163163
if (document.visibilityState === 'hidden') {
164-
if (this.doRequest()) {
164+
if (this.doRequest(true)) {
165165
let flush = this.rum.sendBeacon;
166166
let backup = this.rum.sendFetch;
167167

168168
if (!this.config.useBeacon) {
169169
[flush, backup] = [backup, flush];
170170
}
171171

172-
const req = this.createRequest();
172+
const req = this.createRequest(true);
173173
flush(req)
174174
.catch(() => backup(req))
175175
.catch(() => {
@@ -224,16 +224,24 @@ export class Dispatch {
224224
}
225225
}
226226

227-
private doRequest(): boolean {
228-
return this.enabled && this.eventCache.hasEvents();
227+
private doRequest(flushCandidates = false): boolean {
228+
if (!this.enabled) {
229+
return false;
230+
}
231+
232+
if (flushCandidates && this.eventCache.hasCandidates()) {
233+
return true;
234+
}
235+
236+
return this.eventCache.hasEvents();
229237
}
230238

231-
private createRequest(): PutRumEventsRequest {
239+
private createRequest(flushCandidates = false): PutRumEventsRequest {
232240
return {
233241
BatchId: v4(),
234242
AppMonitorDetails: this.eventCache.getAppMonitorDetails(),
235243
UserDetails: this.eventCache.getUserDetails(),
236-
RumEvents: this.eventCache.getEventBatch(),
244+
RumEvents: this.eventCache.getEventBatch(flushCandidates),
237245
Alias: this.config.alias
238246
};
239247
}

src/dispatch/__tests__/DataPlaneClient.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,6 @@ describe('DataPlaneClient tests', () => {
371371
const signedRequest: HttpRequest = (
372372
fetchHandler.mock.calls[0] as any
373373
)[0];
374-
console.log('signedRequest :>> ', signedRequest);
375374
expect(signedRequest.headers['Authorization']).toEqual(
376375
headers['Authorization']
377376
);

0 commit comments

Comments
 (0)