Repository navigation
fix(logging): read the trace ID once per log entry and handle a missing trace ID in the log buffer - #1378
Merged
Conversation
…ng trace ID in the log buffer
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #1378 +/- ##
===========================================
- Coverage 80.79% 80.78% -0.01%
===========================================
Files 306 306
Lines 13098 13102 +4
Branches 1562 1563 +1
===========================================
+ Hits 10582 10585 +3
- Misses 2074 2076 +2
+ Partials 442 441 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
4 of 7 tasks
|
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 #1376
Summary
Changes
Race in
PowertoolsLogger.GetLogEntry. The X-Ray trace ID was read twice: once in the null check and again to split it.IPowertoolsConfigurations.XRayTraceIdreadsLambdaTraceProvideror the_X_AMZN_TRACE_IDenvironment variable on every access. When the value was cleared between the two reads, the log call threwNullReferenceExceptioninto user code. It's now read once into a local.Missing trace ID in
LogBuffer.HasEntries,HasEvictionsandClearCurrentInvocationpassed the trace ID straight toConcurrentDictionary, which throwsArgumentNullExceptionfor a null key.AddandGetAndClearalready checked for it. With log buffering enabled and no trace ID (for example outside Lambda),FlushBuffer()failed inside its owntryand then logged a spuriousFailed to flush log buffererror. These three members now treat a missing trace ID as "nothing buffered". The publicClearBuffer()was not affected:LogBufferManageralready swallows exceptions there.User experience
NullReferenceException. Examples are a background task that is still logging when the next invocation starts, or concurrent invocations on runtimes that use the environment variable. With buffering enabled and no trace ID,FlushBuffer()writes aFailed to flush log buffererror.Testing
New
TraceIdTests:nullafterwards: the log call doesn't throw and writes the trace ID it readNullReferenceExceptionatPowertoolsLogger.cs:238(the CI failure in #1376)LogBufferwith no trace ID:HasEntries/HasEvictionsare false andClearCurrentInvocationdoesn't throwArgumentNullExceptionFlushBuffer()with buffering enabled and no trace ID doesn't logFailed to flush log bufferClearBuffer()with buffering enabled and no trace ID doesn't throwdotnet test tests/AWS.Lambda.Powertools.Logging.Tests: 517/517 on net8.0 and net10.0.dotnet test tests/AWS.Lambda.Powertools.ConcurrencyTests, which includesKeyIsolationTests, the test that caught this in CI: 526/526 on net8.0 and net10.0.libraries/: 0 errors._X_AMZN_TRACE_ID) threw on 2,653 of 80,000 calls before this change.Merge danger: two-way door. Blast radius: how the trace ID is read while building a log entry, and the log buffer when there's no trace ID.
Checklist
Please leave checklist items unchecked if they do not apply to your change.
Is this a breaking change?
RFC issue number:
Checklist:
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.