Skip to content

fix(logger): fix exception on flush without buffer #6794

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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

tonnico
Copy link
Contributor

@tonnico tonnico commented Jun 11, 2025

Issue number: #6793

Summary

Changes

Please provide a summary of what's being changed
earlier exit when no buffer config is set.

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.

@tonnico tonnico requested a review from a team as a code owner June 11, 2025 09:16
@tonnico tonnico requested a review from leandrodamascena June 11, 2025 09:16
@pull-request-size pull-request-size bot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Jun 11, 2025
Copy link

@leandrodamascena leandrodamascena linked an issue Jun 21, 2025 that may be closed by this pull request
@github-actions github-actions bot added the bug Something isn't working label Jun 21, 2025
Copy link

codecov bot commented Jun 21, 2025

Codecov Report

Attention: Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.

Project coverage is 96.21%. Comparing base (a5482c8) to head (aaca9de).
Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
aws_lambda_powertools/logging/logger.py 0.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #6794   +/-   ##
========================================
  Coverage    96.21%   96.21%           
========================================
  Files          273      273           
  Lines        12691    12691           
  Branches       946      946           
========================================
  Hits         12211    12211           
  Misses         375      375           
  Partials       105      105           

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

Hey @tonnico thanks for sending this PR. Your fork doesn't allow modification, so, can you please add this test to make sure we are testing this situation?

File: https://github.com/tonnico/powertools-lambda-python/blob/c2dd26f297cfcb8834cc0ecd96f256259a5acd9d/tests/functional/logger/required_dependencies/test_powertools_logger_buffer.py

def test_flush_buffer_without_buffer_config(stdout, service_name, lambda_context, monkeypatch):
    # Set initial trace ID for first Lambda invocation
    monkeypatch.setenv(constants.XRAY_TRACE_ID_ENV, "1-67c39786-5908a82a246fb67f3089263f")

    # GIVEN A logger without buffer configuration
    logger = Logger(level="DEBUG", service=service_name, stream=stdout)

    @logger.inject_lambda_context(flush_buffer_on_uncaught_error=True)
    def handler(event, context):
        # Log messages that should be flushed when an exception occurs
        logger.debug("this log line will be flushed after error - 1")
        logger.debug("this log line will be flushed after error - 2")
        raise ValueError("Test error")

    # WHEN Invoking the handler and expecting a ValueError
    # AND flush_buffer_on_uncaught_error is True but there is no logger buffer configuration
    with pytest.raises(ValueError):
        handler({}, lambda_context)

    # THEN Verify that buffered log messages are flushed without any exception
    log = capture_multiple_logging_statements_output(stdout)
    assert len(log) == 2, "Expected two log messages to be flushed"

@leandrodamascena leandrodamascena changed the title fix: exception on flush without buffer fix(logger): fix exception on flush without buffer Jun 22, 2025
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/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: Missing _buffer_config check before in flush_buffer
2 participants