feat(logging): Structured scope support for Lambda JSON log format in Amazon.Lambda.Logging.AspNetCore - #2530
Open
Lanayx wants to merge 3 commits into
Open
feat(logging): Structured scope support for Lambda JSON log format in Amazon.Lambda.Logging.AspNetCore#2530Lanayx wants to merge 3 commits into
Lanayx wants to merge 3 commits into
Conversation
When AWS_LAMBDA_LOG_FORMAT=JSON and IncludeScopes=true, scope state objects
implementing IEnumerable<KeyValuePair<string, object>> have their key/value
entries appended to the message template (as {key} placeholders) and the
parameters array, so they are emitted as named JSON properties by the Lambda
JSON formatter.
Non-structured scopes are silently ignored. Existing behavior (scopes disabled,
text-format logging, no scopes) is unchanged.
Closes aws#2122
Co-authored-by: Lanayx <3329606+Lanayx@users.noreply.github.com>
…port feat(logging): Structured scope support for Lambda JSON log format in Amazon.Lambda.Logging.AspNetCore
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.
Scope properties were silently dropped when
AWS_LAMBDA_LOG_FORMAT=JSON. Addresses aws/aws-lambda-dotnet#2122. The final contribution should targetaws/aws-lambda-dotnet:master. Closes #2122.Changes
LambdaILogger.cs— In the JSON format path, whenIncludeScopes=true, iterates theScopeProviderand for each scope implementingIEnumerable<KeyValuePair<string, object>>, appends{key}placeholders to the message template and the corresponding values to the parameters array. This is necessary because the Lambda JSON formatter (RuntimeSupport) matches template placeholders positionally to args to emit named JSON properties — values without a matching placeholder are ignored. Non-structured scopes (plain strings etc.), null keys, and{OriginalFormat}entries are silently skipped. Non-JSON / scopes-disabled paths are unchanged.LoggingTests.cs— Six focused tests covering: single KV scope, nested scopes, scopes disabled, no-scope template preservation, null scope value, and non-structured scope.README.md— Documents structured scope behavior in Lambda JSON mode.Example
Scope properties are appended after message-template properties, so message positional args are unaffected. Nested scopes are collected in provider-enumeration order (outermost first).
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.