Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: aws-powertools/powertools-lambda-python
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.1.1
Choose a base ref
...
head repository: aws-powertools/powertools-lambda-python
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.1.2
Choose a head ref
  • 11 commits
  • 5 files changed
  • 1 contributor

Commits on Aug 15, 2020

  1. Verified

    This commit was signed with the committer’s verified signature.
    heitorlessa Heitor Lessa
    Copy the full SHA
    106ded0 View commit details
  2. Verified

    This commit was signed with the committer’s verified signature.
    heitorlessa Heitor Lessa
    Copy the full SHA
    c6cf2af View commit details

Commits on Aug 16, 2020

  1. Merge pull request #109 from heitorlessa/docs/tracer-reuse

    docs: clarify Tracer auto_patch as per #108
    heitorlessa authored Aug 16, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    32549c8 View commit details
  2. fix: return subclass #107

    heitorlessa committed Aug 16, 2020

    Verified

    This commit was signed with the committer’s verified signature.
    heitorlessa Heitor Lessa
    Copy the full SHA
    ba3eb2e View commit details
  3. Verified

    This commit was signed with the committer’s verified signature.
    heitorlessa Heitor Lessa
    Copy the full SHA
    1291505 View commit details
  4. Verified

    This commit was signed with the committer’s verified signature.
    heitorlessa Heitor Lessa
    Copy the full SHA
    b468004 View commit details
  5. Verified

    This commit was signed with the committer’s verified signature.
    heitorlessa Heitor Lessa
    Copy the full SHA
    1eafdf4 View commit details
  6. chore: suppress LGTM alert

    We don't initialize logging.Logger as we use an inner Logger and obj proxy instead.
    heitorlessa committed Aug 16, 2020

    Verified

    This commit was signed with the committer’s verified signature.
    heitorlessa Heitor Lessa
    Copy the full SHA
    75b2c16 View commit details
  7. Merge pull request #110 from heitorlessa/improv/logger-auto-complete

    improv: logger autocomplete for PyCharm
    heitorlessa authored Aug 16, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    6215fd6 View commit details
  8. Verified

    This commit was signed with the committer’s verified signature.
    heitorlessa Heitor Lessa
    Copy the full SHA
    d391867 View commit details
  9. Merge pull request #111 from heitorlessa/chore/bump-1.1.2

    chore: bump version to 1.1.2
    heitorlessa authored Aug 16, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    6b66e0b View commit details
Showing with 37 additions and 7 deletions.
  1. +5 −0 CHANGELOG.md
  2. +7 −2 aws_lambda_powertools/logging/logger.py
  3. +7 −2 docs/content/core/tracer.mdx
  4. +1 −1 pyproject.toml
  5. +17 −2 tests/functional/test_logger.py
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.1.2] - 2020-08-16
### Fixed
- **Docs**: Clarify confusion on Tracer reuse and `auto_patch=False` statement
- **Logger**: Autocomplete for log statements in PyCharm

## [1.1.1] - 2020-08-14
### Fixed
- **Logger**: Regression on `Logger` level not accepting `int` i.e. `Logger(level=logging.INFO)`
9 changes: 7 additions & 2 deletions aws_lambda_powertools/logging/logger.py
Original file line number Diff line number Diff line change
@@ -34,7 +34,11 @@ def _is_cold_start() -> bool:
return cold_start


class Logger:
# PyCharm does not support autocomplete via getattr
# so we need to return to subclassing removed in #97
# All methods/properties continue to be proxied to inner logger
# https://github.com/awslabs/aws-lambda-powertools-python/issues/107
class Logger(logging.Logger): # lgtm [py/missing-call-to-init]
"""Creates and setups a logger to format statements in JSON.
Includes service name and any additional key=value into logs
@@ -187,7 +191,8 @@ def _configure_sampling(self):
self.log_level = logging.DEBUG
except ValueError:
raise InvalidLoggerSamplingRateError(
f"Expected a float value ranging 0 to 1, but received {self.sampling_rate} instead. Please review POWERTOOLS_LOGGER_SAMPLE_RATE environment variable." # noqa E501
f"Expected a float value ranging 0 to 1, but received {self.sampling_rate} instead."
f"Please review POWERTOOLS_LOGGER_SAMPLE_RATE environment variable."
)

def inject_lambda_context(self, lambda_handler: Callable[[Dict, Any], Any] = None, log_event: bool = False):
9 changes: 7 additions & 2 deletions docs/content/core/tracer.mdx
Original file line number Diff line number Diff line change
@@ -199,6 +199,11 @@ async def collect_payment(charge_id):

Tracer keeps a copy of its configuration after the first initialization. This is useful for scenarios where you want to use Tracer in more than one location across your code base.

<Note type="warning">
When reusing Tracer in Lambda Layers, or in multiple modules, <strong>do not set <code>auto_patch=False</code></strong>, because import order matters.
<br/><br/>This can result in the first Tracer config being inherited by new instances, and their modules not being patched.
</Note><br/>

```python:title=lambda_handler.py
# handler.py
from aws_lambda_powertools import Tracer
@@ -214,8 +219,8 @@ def handler(event, context):
```python:title=another_file.py
from aws_lambda_powertools import Tracer
# highlight-start
# new instance using existing configuration with auto patching overriden
tracer = Tracer(auto_patch=False)
# new instance using existing configuration
tracer = Tracer(service="payment")
# highlight-end
```

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "aws_lambda_powertools"
version = "1.1.1"
version = "1.1.2"
description = "Python utilities for AWS Lambda functions including but not limited to tracing, logging and custom metric"
authors = ["Amazon Web Services"]
classifiers=[
19 changes: 17 additions & 2 deletions tests/functional/test_logger.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import inspect
import io
import json
import logging
@@ -295,7 +296,7 @@ def test_logger_children_propagate_changes(stdout):
assert child.parent.name == "order"


def test_logger_child_not_set_returns_same_logger(stdout):
def test_logger_child_not_set_returns_same_logger():
# GIVEN two Loggers are initialized with the same service name
# WHEN child param isn't set
logger_one = Logger(service="something")
@@ -308,7 +309,7 @@ def test_logger_child_not_set_returns_same_logger(stdout):
assert logger_one.name is logger_two.name


def test_logger_level_case_insensitive(stdout):
def test_logger_level_case_insensitive():
# GIVEN a Loggers is initialized
# WHEN log level is set as "info" instead of "INFO"
logger = Logger(level="info")
@@ -344,3 +345,17 @@ def test_logger_level_env_var_as_int(monkeypatch):
monkeypatch.setenv("LOG_LEVEL", 50)
with pytest.raises(ValueError, match="Unknown level: '50'"):
Logger()


def test_logger_record_caller_location(stdout):
# GIVEN Logger is initialized
logger = Logger(stream=stdout)

# WHEN log statement is run
logger.info("log")

# THEN 'location' field should have
# the correct caller resolution
caller_fn_name = inspect.currentframe().f_code.co_name
log = capture_logging_output(stdout)
assert caller_fn_name in log["location"]