Skip to content

Commit 339ab09

Browse files
authored
feat: keep earliest event when cache is full (#537)
* chore: drop new events when event cache is full * add doc * words
1 parent b9823bd commit 339ab09

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/event-cache/EventCache.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,11 @@ export class EventCache {
216216
}
217217

218218
if (this.events.length === this.config.eventCacheSize) {
219-
// Make room in the cache by dropping the oldest event.
220-
this.events.shift();
219+
// Drop newest event and keep the older ones
220+
// 1. Older events tend to be more relevant, such as session start
221+
// or performance entries that are attributed to web vitals
222+
// 2. Dropping an old event requires linear time
223+
return;
221224
}
222225

223226
// The data plane service model (i.e., LogEvents) does not adhere to the

src/event-cache/__tests__/EventCache.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ describe('EventCache tests', () => {
158158
expect(eventCache.getEventBatch()[0].type).toEqual(EVENT2_SCHEMA);
159159
});
160160

161-
test('when cache size reached, recordEvent drops oldest event', async () => {
161+
test('when cache size reached, recordEvent drops the newest event', async () => {
162162
// Init
163163
const EVENT1_SCHEMA = 'com.amazon.rum.event1';
164164
const EVENT2_SCHEMA = 'com.amazon.rum.event2';
@@ -175,7 +175,7 @@ describe('EventCache tests', () => {
175175
{
176176
id: expect.stringMatching(/[0-9a-f\-]+/),
177177
timestamp: new Date(),
178-
type: EVENT2_SCHEMA,
178+
type: EVENT1_SCHEMA,
179179
metadata: `{"version":"1.0.0","aws:client":"${INSTALL_MODULE}","aws:clientVersion":"${WEB_CLIENT_VERSION}"}`,
180180
details: '{}'
181181
}

0 commit comments

Comments
 (0)