Repository navigation
Fix JSON log parameter ordering - #2506
Conversation
|
Reporter of #2468 here. The approach looks right, two practical notes:
Also worth knowing: #2474 inserts a block immediately before the |
|
Thanks for both notes. I checked them against the current repository state: #2545 retired the |
There was a problem hiding this comment.
Pull request overview
Fixes JSON structured logging by aligning custom ILogger state values with template placeholders.
Changes:
- Adds name-based parameter ordering and template parsing.
- Adds regression and edge-case tests.
- Adds an AutoVer patch entry.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
LambdaILogger.cs |
Implements parameter reordering and parsing. |
LoggingTests.cs |
Tests ordering and template edge cases. |
.autover/changes/58593c38-0c20-4fee-993c-15ea9f1f49fb.json |
Records the patch change. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| if (UsesPositionalArguments(templateProperties)) | ||
| { | ||
| return GetPropertyValues(properties); | ||
| } |
GarrettBeatty
left a comment
There was a problem hiding this comment.
Reviewed the diff for #2506 (JSON log parameter ordering). 6 findings — no confirmed blockers. Two major items are open questions that depend on Amazon.Lambda.Core.LambdaLogger.Log, whose body isn't in this diff.
1. [major] LambdaILogger.cs · OrderParametersByMessageTemplate — Appending unconsumed state values and inserting null for missing placeholders could alter the observable JSON (extra/renamed fields, or a Missing: null field that didn't exist before). Can't confirm from the diff because LambdaLogger.Log's handling of surplus/null args isn't included. Can you confirm the downstream behavior — or whether reordering is the right layer vs. name-based assignment?
2. [major] LambdaILogger.cs — Duplicate-placeholder handling is asymmetric: when state has more same-name values than the template references, the extra is appended as an unnamed trailing value; when the template references more than state provides, the surplus becomes null. Neither direction has a test pinning the intended output.
3. [major] LambdaILogger.cs · UsesPositionalArguments — Strips a leading @ but not $ before int.TryParse, so {$0} is misclassified as non-positional and falls into the name-based path. No test covers $-prefixed positional templates.
4. [minor] LambdaILogger.cs · ParseTemplateProperties cache — if (Count < MAXSIZE) TryAdd(...) is check-then-act: under concurrency the cache can exceed 1024 (bounded overflow) and grow with high-cardinality templates. It's a process-lifetime static on a logging hot path.
5. [minor] LoggingTests.cs — The new facts assert the captured object[] parameter array + MessageTemplate, not serialized JSON. Correct seam for the reordering logic, but they don't prove observable output — relevant given finding #1.
6. [minor] .autover/changes/…json — Change type is Patch; if finding #1 confirms an observable output change, Minor would be more accurate.
- Use one cached template parser for both the scope collision check and the reordering of state values. ExtractTemplatePropertyNames is now a wrapper over it, so it keeps the existing parity test with RuntimeSupport. The test now also checks that placeholders are found in the same order. - Only reorder state values when every placeholder name is found in the state. Otherwise keep the state order, which still binds correctly for custom states whose keys differ from the placeholder names but whose values are already in template order. - Simplify repeated placeholder handling and the positional template check, which now mirrors the RuntimeSupport rule.
aa32a8a to
62e6ceb
Compare
The previous commits rewrote LambdaILogger.cs and LoggingTests.cs with LF line endings. Lines unchanged from master keep their original endings and new lines use CRLF. No content changes.
Issue #, if available:
Fixes #2468
Description of changes:
When the JSON logging path receives a custom
ILoggerstate whose enumerationorder differs from
{OriginalFormat}, order the callback arguments by messagetemplate placeholder name instead of by state position.
The implementation:
and positional templates;
1,024-entry soft cache cap as RuntimeSupport; and
cases above, plus the required AutoVer patch change file.
Validation:
dotnet test Libraries/test/Amazon.Lambda.Logging.AspNetCore.Tests/Amazon.Lambda.Logging.AspNetCore.Tests.csproj --framework net10.0 --configuration Debug(20 passed)dotnet test Libraries/test/Amazon.Lambda.Logging.AspNetCore.Tests/Amazon.Lambda.Logging.AspNetCore.Tests.csproj --framework net10.0 --configuration Release(20 passed)dotnet build Libraries/test/Amazon.Lambda.Logging.AspNetCore.Tests/Amazon.Lambda.Logging.AspNetCore.Tests.csproj --configuration Release --framework net8.0(0 warnings, 0 errors)master(fdb84c71)git -c core.whitespace=cr-at-eol diff --checkBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.