Description
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
powertools-lambda-typescript/packages/logger/src/Logger.ts
Lines 1386 to 1392 in cab716d
flushBuffer
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
Type
Projects
Status