Description
Is your feature request related to a problem? Please describe.
My team uses Powertools core utilities (Logging, Metrics and Tracing) in one of our Lambda functions.
In that, we rely on LoggingUtils.appendKeys
and metricsLogger().putProperty
to append specific request-related key/value pairs that improve our ability to debug issues and run adhoc queries using CloudWatch Logs Insights.
We've discovered an issue with our logging that values set via LoggingUtils.appendKeys
are not cleared after the request is done, they instead get carried over to the following requests unless those key/value pairs are overridden which led to wrong key/value pairs being associated with a given request's log lines.
This is an unexpected behaviour, our assumption was that logging properties set in a given request, would just be scoped to that request.
Describe the solution you'd like
Setting logging properties via LoggingUtils.appendKeys
should be scoped to a request i.e. they should be automatically cleared after the request is completed.
The behaviour where properties are carried over from one request to the next, opens a door for logging bugs as in Lambda.
Describe alternatives you've considered
The main alternative, and current mitigation, is to explicitly clear the logging properties using LoggingUtils.removeKeys
. While it achieves the same result, it's cumbersome - as it requires tracking the keys to clear.