Skip to content

Feature request: Clear log buffer before starting next one #3705

Closed
@zirkelc

Description

@zirkelc

Hi,

I went through the code of the new log buffering feature and noticed a potential memory issue. The way it is currently implemented, both clearBuffer() and flushBuffer() will reset the log items only for the current X-Ray Trace ID:

clearBuffer

public clearBuffer(): void {
const traceId = this.envVarsService.getXrayTraceId();
if (traceId === undefined) {
return;
}
this.#buffer?.delete(traceId);
}

flushBuffer

this.#buffer?.delete(traceId);

However, that means if the Logger is created outside of the handler and is not explicitly cleared, or flushed through an error, the buffer will keep logs from previous invocations with different X-Ray Trace IDs. For example, a Lambda instance that runs every few minutes will be re-used and eventually fill up the buffer with log items.

Since the buffer is implemented as a Map, I think calling this.#buffer?.clear() instead of this.#buffer?.delete(traceId) should have the same effect without the potential memory issue.

Metadata

Metadata

Assignees

Labels

completedThis item is complete and has been merged/shippeddocumentationImprovements or additions to documentationfeature-requestThis item refers to a feature request for an existing or new utilityloggerThis item relates to the Logger Utility

Type

No type

Projects

Status

Shipped

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions