Skip to content

fix(logger): force Logger to use local timezone when UTC flag is not set #3168

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

Merged
merged 18 commits into from
Oct 13, 2023

Conversation

roger-zhangg
Copy link
Member

@roger-zhangg roger-zhangg commented Oct 4, 2023

Issue number: #3154

Summary

Changes

Previously logging ignores TZ env value, this fix make logging follows local TZ value when UTC flag is not set

User experience

UX not affected

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.

@roger-zhangg roger-zhangg requested a review from a team October 4, 2023 01:54
@pull-request-size pull-request-size bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Oct 4, 2023
@codecov-commenter
Copy link

codecov-commenter commented Oct 4, 2023

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (bf2df4f) 95.96% compared to head (1143968) 95.96%.
Report is 2 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    #3168   +/-   ##
========================================
  Coverage    95.96%   95.96%           
========================================
  Files          195      195           
  Lines         8381     8382    +1     
  Branches      1562     1562           
========================================
+ Hits          8043     8044    +1     
  Misses         276      276           
  Partials        62       62           
Files Coverage Δ
aws_lambda_powertools/logging/formatter.py 100.00% <100.00%> (ø)

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

@leandrodamascena leandrodamascena changed the title fix(logging): Fix logging to follow Env Var "TZ" in lambda fix(logger): force Logger to use local timezone when UTC flag is not set Oct 4, 2023
@leandrodamascena leandrodamascena linked an issue Oct 5, 2023 that may be closed by this pull request
@pull-request-size pull-request-size bot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 5, 2023
@boring-cyborg boring-cyborg bot added the documentation Improvements or additions to documentation label Oct 6, 2023
@pull-request-size pull-request-size bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Oct 6, 2023
Copy link
Contributor

@leandrodamascena leandrodamascena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @roger-zhangg! Another PR with simple and extremely high-quality solutions. You're smashing it, man.

I left some comments we need to address before merging this!

@boring-cyborg boring-cyborg bot added the dependencies Pull requests that update a dependency file label Oct 9, 2023
@leandrodamascena leandrodamascena self-requested a review October 10, 2023 15:18
Copy link
Contributor

@leandrodamascena leandrodamascena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@heitorlessa or @rubenfonseca, can you make a last review of this PR, please?

LGTM! Approving!

@roger-zhangg
Copy link
Member Author

e2e test output

poetry run pytest tests/e2e/logger/test_logger.py
/local/home/ruojiazh/projects/aws-lambda-powertools-python/.venv/lib/python3.10/site-packages/pytest_benchmark/logger.py:46: PytestBenchmarkWarning: Benchmarks are automatically disabled because xdist plugin is active.Benchmarks cannot be performed reliably in a parallelized environment.
  warner(PytestBenchmarkWarning(text))
================================================================== test session starts ==================================================================
platform linux -- Python 3.10.2, pytest-7.4.2, pluggy-1.2.0 -- /local/home/ruojiazh/projects/aws-lambda-powertools-python/.venv/bin/python
cachedir: .pytest_cache
benchmark: 4.0.0 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10 warmup=False warmup_iterations=100000)
rootdir: /local/home/ruojiazh/projects/aws-lambda-powertools-python/tests/e2e
configfile: pytest.ini
plugins: typeguard-2.13.3, ddtrace-1.15.2, anyio-3.7.1, cov-4.1.0, xdist-3.3.1, mock-3.11.1, benchmark-4.0.0, socket-0.6.0, asyncio-0.21.1
asyncio: mode=strict
collected 13 items                                                                                                                                      

tests/e2e/logger/test_logger.py::test_basic_lambda_logs_visible PASSED                                                                            [  7%]
tests/e2e/logger/test_logger.py::test_lambda_tz[%z-US/Eastern-False] PASSED                                                                       [ 15%]
tests/e2e/logger/test_logger.py::test_lambda_tz[%z-US/Eastern-True] PASSED                                                                        [ 23%]
tests/e2e/logger/test_logger.py::test_lambda_tz[%z-UTC-False] PASSED                                                                              [ 30%]
tests/e2e/logger/test_logger.py::test_lambda_tz[%z-UTC-True] PASSED                                                                               [ 38%]
tests/e2e/logger/test_logger.py::test_lambda_tz[%z-Asia/Shanghai-False] PASSED                                                                    [ 46%]
tests/e2e/logger/test_logger.py::test_lambda_tz[%z-Asia/Shanghai-True] PASSED                                                                     [ 53%]
tests/e2e/logger/test_logger.py::test_lambda_tz[None-US/Eastern-False] PASSED                                                                     [ 61%]
tests/e2e/logger/test_logger.py::test_lambda_tz[None-US/Eastern-True] PASSED                                                                      [ 69%]
tests/e2e/logger/test_logger.py::test_lambda_tz[None-UTC-False] PASSED                                                                            [ 76%]
tests/e2e/logger/test_logger.py::test_lambda_tz[None-UTC-True] PASSED                                                                             [ 84%]
tests/e2e/logger/test_logger.py::test_lambda_tz[None-Asia/Shanghai-False] PASSED                                                                  [ 92%]
tests/e2e/logger/test_logger.py::test_lambda_tz[None-Asia/Shanghai-True] PASSED                                                                   [100%]

=================================================================== warnings summary ====================================================================
.venv/lib/python3.10/site-packages/ddtrace/internal/module.py:220
  /local/home/ruojiazh/projects/aws-lambda-powertools-python/.venv/lib/python3.10/site-packages/ddtrace/internal/module.py:220: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
    self.loader.exec_module(module)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
======================================================= 13 passed, 1 warning in 215.94s (0:03:35) =======================================================
(23-10-10 15:59:23) <0> [~/projects/aws-lambda-powertools-python]  

Copy link
Contributor

@heitorlessa heitorlessa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks mostly good - E2E test should be split, and Lambda Handler needs comments.

A rule of thumb is that the minute you need If/Else, For/While Loops in a test, you need to break them.

We run tests in parallel so there isn't a penalty for adding more granular E2E tests in this case.

@leandrodamascena leandrodamascena self-requested a review October 12, 2023 16:15
Copy link
Contributor

@leandrodamascena leandrodamascena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@heitorlessa heitorlessa merged commit 5997da5 into aws-powertools:develop Oct 13, 2023
@sonarqubecloud
Copy link

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 4 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file documentation Improvements or additions to documentation 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.

Bug: Logger Timestamps Misaligned with Local Time
4 participants