Skip to content

fix(logger): include the call stack when stack_info=True - #8951

Open
sumedh-aerram wants to merge 1 commit into
aws-powertools:developfrom
sumedh-aerram:fix/logger-stack-info
Open

sumedh-aerram wants to merge 1 commit into
aws-powertools:developfrom
sumedh-aerram:fix/logger-stack-info

Conversation

@sumedh-aerram

Copy link
Copy Markdown
Contributor

Issue number:

closes #8950

Summary

Changes

LambdaPowertoolsFormatter lists stack_info as a reserved LogRecord attribute but never wrote it, so logger.info(..., stack_info=True) dropped the call stack. format() now adds record.stack_info under a stack_info key. The value is None unless the caller passes stack_info=True, and None values are already stripped, so log lines without it are unchanged. A stack_info value set through append_keys is kept, the same way exception and exception_name work today.

The Logger docs get a short "Logging the call stack" section with an example and its output. The logger agent skill reference is regenerated from the docs (only this section).

User experience

Before: logger.info("charging", stack_info=True) printed the log line without the stack. After: the line has "stack_info": "Stack (most recent call last):\n File ...", ending at the caller's frame, as the standard library prints it. Buffered records flushed later keep it too.

Verification

  • New functional tests, public API only: test_logger_logs_stack_info_when_requested, test_logger_omits_stack_info_by_default, and test_logger_buffer_keeps_stack_info_on_flush. The two that expect the stack fail on develop and pass with the fix.
  • tests/functional/logger and tests/unit/logger: 266 passed and 1 skipped on Python 3.10, 267 passed on 3.14. Full pytest tests/functional tests/unit -m "not perf": 4182 passed, 73 skipped. ruff format --check, ruff check, mypy and the pre-commit hooks (including markdownlint) pass.
  • I also checked DatadogLogFormatter, log_record_order, serialize_stacktrace=False, exc_info together with stack_info, and a buffered debug line. No AWS service is involved, so there's no service-side validation.

I used an AI assistant (Claude) to help find and write this change. I ran every check above and reviewed the diff myself.


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.

@sumedh-aerram
sumedh-aerram requested a review from a team as a code owner December 4, 2026 00:27
@sumedh-aerram
sumedh-aerram requested a review from svozza December 4, 2026 00:27
@boring-cyborg boring-cyborg Bot added documentation Improvements or additions to documentation logger tests labels Dec 4, 2026
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Dec 4, 2026
@sonarqubecloud

sonarqubecloud Bot commented Dec 4, 2026

Copy link
Copy Markdown

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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 drops the call stack when a log call passes stack_info=True

1 participant