question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Logger clear_state flip removing structure keys

See original GitHub issue

Using the clear_state argument in the logger decorator for lambda handlers is destroying the default structured keys.

What were you trying to accomplish? Just trying to get some lambda logs with custom keys, which ideally would be cleaned up after each warm call, such that those custom key values do not trickle to the next invocation.

Expected Behavior

Using the clear_state argument should not remove the default structured keys. Those should remain fixed. Only custom keys should be removed upon new invocation.

Current Behavior

Currently, default structured keys are being removed from the get-go.

Steps to Reproduce (for bugs)

First, this:

from aws_lambda_powertools import logging
from aws_lambda_powertools.utilities.typing import LambdaContext


logger = logging.Logger()

@logger.inject_lambda_context(clear_state=False)
def lambda_handler(event: dict, context: LambdaContext):
    logger.info("HEREEE")

Output:

{
    "level": "INFO",
    "location": "lambda_handler:21",
    "message": "HEREEE",
    "timestamp": "2022-03-29 17:53:56,985+0000",
    "service": "service_undefined",
    "cold_start": true,
    "function_name": "alex-test-layers",
    "function_memory_size": "1024",
    "function_arn": "arn:aws:lambda:us-west-2:111111111111:function:alex-test-layers",
    "function_request_id": "a1453466-2abe-4a55-ad9e-640e745f4133",
    "xray_trace_id": "1-624347b4-589b3226782e49797249edb1"
}

Now this clear_state=True

from aws_lambda_powertools import logging
from aws_lambda_powertools.utilities.typing import LambdaContext


logger = logging.Logger()

@logger.inject_lambda_context(clear_state=True)
def lambda_handler(event: dict, context: LambdaContext):
    logger.info("HEREEE")

Output:

{
    "message": "HEREEE",
    "service": "service_undefined",
    "cold_start": true,
    "function_name": "alex-test-layers",
    "function_memory_size": "1024",
    "function_arn": "arn:aws:lambda:us-west-2:111111111111:function:alex-test-layers",
    "function_request_id": "e3cf7717-88ea-43dc-b80c-57754bc6b8c9",
    "xray_trace_id": "1-62435f24-54e5827e68d838640494dca4"
}

Environment

  • Powertools version used: aws-lambda-powertools==1.25.5
  • Packaging format (Layers, PyPi): Layers
  • AWS Lambda function runtime: Python 3.8
  • Debugging logs: Above.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:11 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
eliasbrangecommented, Apr 6, 2022

@heitorlessa PR is up and running! #1095

1reaction
heitorlessacommented, Apr 1, 2022

Thanks to your super high quality bug report we managed to reproduce and improved tests as part of the fix - the latest version 1.25.6 has this fix now. Lambda Layers upcoming version 16 will take a few hours to be available in multiple AWS commercial regions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Deleting the system logger structures - IBM
After the structure has been deleted, the VARY OPERLOG,HARDCPY command can be used to cause consoles to use a log stream again. For...
Read more >
Serviceability Best Practices Guide for Cisco Unified ICM ...
Live, Play, and Learn, Cisco Store, and Flip Gift Card are service marks; and Access Registrar, ... logger in order to remove the...
Read more >
Guile Reference Manual - GNU.org
6.6.20.1 Alist Key Equality; 6.6.20.2 Adding or Setting Alist Entries; 6.6.20.3 Retrieving Alist Entries; 6.6.20.4 Removing Alist Entries; 6.6.20.5 Sloppy ...
Read more >
Microsoft Media Foundation - Win32 apps
Specifies flags for a 3D12_VIDEO_ENCODER_RATE_CONTROL structure. ... Removes all key/value pairs from the object's attribute list.
Read more >
8th Wall Documentation
Delete the connected domain from your 8th Wall project. Clean up and DNS records added ... Self-hosted Projects require an App Key to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found