Skip to content

Conversation

@leandrodamascena
Copy link
Contributor

@leandrodamascena leandrodamascena commented May 17, 2024

Issue number: #4362

Summary

Changes

The PR https://github.com/aws-powertools/powertools-lambda-python/pull/4295/files potentially introduced a breaking change when customer is using many Logger instances with the same service name. This bug occurs locally or running in the Lambda environment.

Example:

validate_log.py

from collections import namedtuple
from aws_lambda_powertools.event_handler import (
    APIGatewayRestResolver,)
from aws_lambda_powertools.logging import correlation_paths
from aws_lambda_powertools.utilities.typing import LambdaContext
from aws_lambda_powertools import Logger

from event import EVENT

from validate_log1 import *

logger = Logger()
app = APIGatewayRestResolver(enable_validation=True)

@app.get("/hello")
def get_todos():
    return {"todos": "OK"}


@logger.inject_lambda_context(
    correlation_id_path=correlation_paths.API_GATEWAY_HTTP, log_event=True
)
def lambda_handler(request: dict, context: LambdaContext) -> dict:
    return app.resolve(request, context)


def lambda_context():
    lambda_context = {
        "function_name": "test",
        "memory_limit_in_mb": 128,
        "invoked_function_arn": "arn:aws:lambda:eu-west-1:809313241:function:test",
        "aws_request_id": "52fdfc07-2182-154f-163f-5f0f9a621d72",
    }

    return namedtuple("LambdaContext", lambda_context.keys())(*lambda_context.values())

lambda_handler(EVENT, lambda_context())

validate_log1.py

from aws_lambda_powertools import Logger

logger = Logger()

output

(venv) ➜  bug-log python validate_log.py                          
Traceback (most recent call last):
  File "/Users//DEV/powertools/tmp-testes/bug-log/validate_log.py", line 37, in <module>
    lambda_handler(EVENT, lambda_context())
  File "/Users//DEV/powertools/tmp-testes/bug-log/venv/lib/python3.10/site-packages/aws_lambda_powertools/logging/logger.py", line 455, in decorate
    self.append_keys(cold_start=cold_start, **lambda_context.__dict__)
  File "/Users//DEV/powertools/tmp-testes/bug-log/venv/lib/python3.10/site-packages/aws_lambda_powertools/logging/logger.py", line 603, in append_keys
    self.registered_formatter.append_keys(**additional_keys)
AttributeError: 'NoneType' object has no attribute 'append_keys'

User experience

Please share what the user experience looks like before and after this change

Checklist

If your change doesn't seem to apply, please leave them unchecked.

Is this a breaking change?

RFC issue number:

Checklist:

  • Migration process documented
  • Implement warnings (if it can live side by side)

Acknowledgment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@leandrodamascena leandrodamascena requested a review from a team May 17, 2024 19:19
@boring-cyborg boring-cyborg bot added documentation Improvements or additions to documentation logger tests labels May 17, 2024
@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label May 17, 2024
@sonarqubecloud
Copy link

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

@github-actions github-actions bot added bug Something isn't working and removed documentation Improvements or additions to documentation labels May 17, 2024
@boring-cyborg boring-cyborg bot added the documentation Improvements or additions to documentation label May 17, 2024
@leandrodamascena leandrodamascena changed the title bug(logger): reverting logger child modification fix(logger): reverting logger child modification May 17, 2024
@github-actions github-actions bot removed the documentation Improvements or additions to documentation label May 17, 2024
@boring-cyborg boring-cyborg bot added the documentation Improvements or additions to documentation label May 17, 2024
@github-actions github-actions bot removed the documentation Improvements or additions to documentation label May 17, 2024
@codecov
Copy link

codecov bot commented May 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.32%. Comparing base (e14e768) to head (427756d).
Report is 454 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4363      +/-   ##
===========================================
- Coverage    96.38%   96.32%   -0.06%     
===========================================
  Files          214      218       +4     
  Lines        10030    10440     +410     
  Branches      1846     1930      +84     
===========================================
+ Hits          9667    10056     +389     
- Misses         259      270      +11     
- Partials       104      114      +10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sthulb sthulb merged commit ded5622 into aws-powertools:develop May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working logger size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants