Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(logger): implement addFilter/removeFilter to address static typing errors #3380

Merged
merged 7 commits into from
Nov 21, 2023

Conversation

heitorlessa
Copy link
Contributor

@heitorlessa heitorlessa commented Nov 21, 2023

Issue number: #3358

Summary

Adds addFilter method that was previously missing so static type checkers are happy.

NOTE: By default, Logger proxies any missing public method or attribute to its private logger (_logger) to avoid any runtime issues, so this wasn't an issue at runtime.

Changes

Please provide a summary of what's being changed

  • Add addFilter public method
  • Add removeFilter public method

Unrelated changes

User experience

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

Experience in adding a filter like it was before but without any mypy errors

import logging
from aws_lambda_powertools.logging import Logger
import secrets

logger = Logger()


class ApiKeyFilter(logging.Filter):
    def filter(self, record):
        if getattr(record, "api_key", None):
            record.api_key = "REDACTED"

        return True


logger.addFilter(ApiKeyFilter())

logger.info("Blah", api_key=secrets.token_urlsafe())

JSON output

{
    "level": "INFO",
    "location": "<module>:18",
    "message": "Blah",
    "timestamp": "2023-11-21 09:59:48,477+0100",
    "service": "service_undefined",
    "api_key": "REDACTED"
}

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.

@heitorlessa heitorlessa requested a review from a team as a code owner November 21, 2023 08:58
@pull-request-size pull-request-size bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Nov 21, 2023
sthulb
sthulb previously approved these changes Nov 21, 2023
@pull-request-size pull-request-size bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Nov 21, 2023
@codecov-commenter
Copy link

codecov-commenter commented Nov 21, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (060ce36) 95.39% compared to head (59e3d72) 95.37%.
Report is 1 commits behind head on develop.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3380      +/-   ##
===========================================
- Coverage    95.39%   95.37%   -0.02%     
===========================================
  Files          208      208              
  Lines         9633     9637       +4     
  Branches      1766      805     -961     
===========================================
+ Hits          9189     9191       +2     
- Misses         330      331       +1     
- Partials       114      115       +1     

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

Copy link

sonarcloud bot commented Nov 21, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 2 Code Smells

No Coverage information No Coverage information
3.3% 3.3% Duplication

@heitorlessa
Copy link
Contributor Author

@sthulb good to go now, ignored Sonar rule in functional test as it doesn't pose any risk (we want to redact sensitive data in our test).

One last CI check (Python 3.11) and passing that it's good to merge. tks

@heitorlessa heitorlessa changed the title feat(logger): implement addFilter to address static typing errors feat(logger): implement addFilter/removeFilter to address static typing errors Nov 21, 2023
@sthulb sthulb merged commit 281f7fd into aws-powertools:develop Nov 21, 2023
17 checks passed
@heitorlessa heitorlessa deleted the logger/filter branch November 21, 2023 10:02
@heitorlessa heitorlessa added the feature New feature or functionality label Nov 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or functionality logger size/M Denotes a PR that changes 30-99 lines, ignoring generated files. tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants