in src/eventbuffer/InMemoryJSONEventBuffer.ts [164:213]
async addItem(item: EventData): Promise<void> {
this.logger.debug(
`Event Reporting - InMemoryJSONEventBuffer - addItem - received event ${JSON.stringify(item)}`
);
const { name, ts, attributes } = item;
// Filter out PII and redundant attributes.
const filteredAttributes =
attributes && this.filterAttributes(attributes, this.attributesToFilter);
const event = { name, ts, ...filteredAttributes };
this.logger.debug(
`Event Reporting - InMemoryJSONEventBuffer - addItem - event after filtering attributes ${JSON.stringify(
event
)}`
);
const size = this.getSize(event);
if (size > InMemoryJSONEventBuffer.MAX_ITEM_SIZE_BYTES_ALLOWED) {
throw new Error(
`Event Reporting - Item to be added has size ${size} bytes. Item cannot exceed max item size allowed of ${InMemoryJSONEventBuffer.MAX_ITEM_SIZE_BYTES_ALLOWED} bytes.`
);
}
if (this.importantEvents.has(name)) {
// Send immediate events and asyncly retry.
this.logger.debug(
`Event Reporting - InMemoryJSONEventBuffer - addItem - sending important event ${JSON.stringify(
event
)}`
);
this.sendEventImmediately({ name, ts, attributes: filteredAttributes });
return;
}
if (this.isFull()) {
this.logger.warn('Event Reporting - Event buffer is full');
throw new Error('Buffer full');
}
this.currentIngestionEvent.payloads.push(event);
this.ingestionEventSize += size;
if (this.bufferItemThresholdReached(size)) {
const currentEvent = this.deepCopyCurrentIngestionEvent(this.currentIngestionEvent);
this.buffer.push(currentEvent);
this.bufferSize += this.ingestionEventSize;
this.currentIngestionEvent = this.initializeAndGetCurrentIngestionEvent();
this.logger.debug(
`Event Reporting - InMemoryJSONEventBuffer - addItem - buffer item threshold reached updated buffer ${JSON.stringify(
this.buffer
)}`
);
}
}