Repository navigation
fix(logger): emit buffered logs when trace ID is unavailable - #8865
leandrodamascena merged 2 commits into
Conversation
- Emit log records immediately when no X-Ray trace ID is available, preventing messages produced during initialization or outside a traced Lambda invocation from being silently dropped. - Preserve existing invocation-scoped buffering when a trace ID is available, including buffer isolation and overflow handling. - Update the logger documentation and example to explain the immediate-emission behavior. - Add functional tests covering immediate emission through the Powertools Logger and external loggers configured with buffering, including verification that emitted records are not duplicated when the buffer is subsequently flushed.
leandrodamascena
left a comment
There was a problem hiding this comment.
Thanks @coughlmao! Emitting right away when there is no trace id is the call I'd have made too, and the early return makes the buffered path easier to read than before. The flush-after test is a good one, it pins that nothing gets written twice. Goes out in 3.42.0, no need to rebase, you'll be in the release notes.
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #8865 +/- ##
===========================================
- Coverage 97.15% 97.14% -0.01%
===========================================
Files 327 327
Lines 16781 16785 +4
Branches 1531 1532 +1
===========================================
+ Hits 16303 16306 +3
- Misses 335 336 +1
Partials 143 143 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
a904747
into
aws-powertools:develop



Issue number: closes #8822
Summary
Changes
_add_log_record_to_buffer()to emit log records immediately when no X-Ray trace ID is available, rather than silently dropping them.LoggerAPI and external loggers configured with buffering.Design decision: I chose to emit records immediately when no trace ID is available, rather than buffering them under a fixed key. Without a trace ID, records cannot be associated with a specific invocation. Immediate emission prevents log loss during initialization and outside Lambda without introducing additional fallback-buffer lifecycle or cross-invocation coordination. This also follows the maintainer's recommendation in the issue discussion.
User experience
Before: When
buffer_configwas enabled, log records emitted while_X_AMZN_TRACE_IDwas unavailable were silently dropped. This affected initialization-phase logs and logs produced outside Lambda. Callingflush_buffer()later did not recover those records.After: Records emitted without an available trace ID are written immediately, so they are not lost. Once a trace ID is available, the existing invocation-scoped buffering behavior continues unchanged.
Verification
Ran the project validation successfully using make pr.
Also ran focused functional tests for the buffering behavior and external logger integration.
No live AWS service validation was performed; the change concerns local logger buffering behavior and was verified through the project's functional and unit test suites.
This contribution was developed with AI assistance. I reviewed the changes and personally ran the tests and checks listed above.
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.