Repository navigation
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.
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



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.