You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe
Currently, logger keys are kept between Lambda invocations unless I manually call remove_keys or structure_logs.
def handler(event, context):
logger.info('log info') # will include key1 & key2 after first invocation
logger.append_keys(key1=body['something'])
logger.info('log log log')
# some code...
logger.append_keys(key2=some_value)
logger.info('log log log')
Currently, if I want to remove all keys added during the lambda I need to run at the start of the lambda:
logger.remove_keys(['key1', 'key2'])
# or
logger.structure_logs()
The problem with the first option is that I don't want to specify all keys manually, I might even forget some keys.
The problem with the second option is that it will be removed in the next major version and it would also delete lambda injected context (if I use @logger.inject_lambda_context)
Describe the solution you'd like
An easy way to remove all keys at the start of a lambda execution
If using @logger.inject_lambda_context remove all keys by default (can be changed with parameter) at the start of each lambda
create a new method: logger.restart_keys(exclude=[])
logger.restart_keys() # will remove all keys
logger.restart_keys(['key2']) # will remove all keys except key2
If you provide guidance, is this something you'd like to contribute?
Yes
Thanks a lot for opening that up @LironEr - just added it to the backlog :)
Following our tenets, I'll implement a toggle you can use in the @inject_lambda_context to clear the state but not as a default, otherwise it'll break customers' current reliance on that today -- We can however make this a default in v2.
Runtime: Python
Is your feature request related to a problem? Please describe
Currently, logger keys are kept between Lambda invocations unless I manually call
remove_keys
orstructure_logs
.Currently, if I want to remove all keys added during the lambda I need to run at the start of the lambda:
The problem with the first option is that I don't want to specify all keys manually, I might even forget some keys.
The problem with the second option is that it will be removed in the next major version and it would also delete lambda injected context (if I use
@logger.inject_lambda_context
)Describe the solution you'd like
An easy way to remove all keys at the start of a lambda execution
@logger.inject_lambda_context
remove all keys by default (can be changed with parameter) at the start of each lambdalogger.restart_keys(exclude=[])
If you provide guidance, is this something you'd like to contribute?
Yes
Additional context
Related issue: aws-powertools/powertools-lambda-python#407 (comment)
The text was updated successfully, but these errors were encountered: