Skip to content

Lambda context data is excluded when using custom formatter and flag clear_state on inject_lambda_context #1042

Closed
@jacobdarrossi

Description

@jacobdarrossi

When we use a custom formatter, inject_lambda_context with clear_state=True stopped having effect

Expected Behavior

The keys appended should be removed in clear_state=True and the context data should be kept. The custom Formatter should not impact this behavior

Current Behavior

When we use a custom formatter to obfuscate sensitive data in our logs, the flag clear_state=True stopped having effect, the context data is no longer logged and the keys appended was not removed in next hot execution. If clear_state is removed, the context data is logged normally

Steps to Reproduce (for bugs)

  1. Create a Formatter than override json_serializer_function
  2. Create a Logger object with this formatter
  3. Use the decorator inject_lambda_function(clear_state=True)
  4. Check the execution logs

Environment

  • Powertools version used: 1.25.1
  • Packaging format (Layers, PyPi): Layer
  • AWS Lambda function runtime: python 3.8

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingp1

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions