AWS powertools documentation change
Summary
Updated documentation for ExtraKeys to introduce temporary scoped context management and revised log buffering configuration syntax. Added code examples for key management, clarified async safety, and updated log buffering property access patterns.
Security assessment
The ExtraKeys changes emphasize automatic key removal to prevent accidental sensitive data retention in logs, though no explicit vulnerability is mentioned. The log buffering updates explicitly document memory limits (MaxBytes) to prevent resource exhaustion attacks, making this a security-aware configuration documentation addition.
Diff
diff --git a/powertools/dotnet/core/logging.md b/powertools/dotnet/core/logging.md index 7ae5a13ba..5119653c3 100644 --- a//powertools/dotnet/core/logging.md +++ b//powertools/dotnet/core/logging.md @@ -56 +56,2 @@ Homepage - * Extra Keys + * Temporary keys with ExtraKeys + * Extra Keys (Single Log Entry) @@ -113 +114,2 @@ Table of contents - * Extra Keys + * Temporary keys with ExtraKeys + * Extra Keys (Single Log Entry) @@ -1163 +1165 @@ Function.cs -## Extra Keys¶ +### Temporary keys with ExtraKeys¶ @@ -1165 +1167,219 @@ Function.cs -Extra keys allow you to append additional keys to a log entry. Unlike `AppendKey`, extra keys will only apply to the current log entry. +The `ExtraKeys` method allows temporary modification of the Logger's context without manual cleanup. It's useful for adding context keys to specific workflows while maintaining the logger's overall state. + +Keys are automatically removed when the scope ends, eliminating the need to manually call `AppendKey` and `RemoveKeys`. + +Using DictionaryUsing TuplesNested ScopesExample CloudWatch Logs excerpt + + + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + +| + + + /** + * Handler for requests to Lambda function. + */ + public class Function + { + [Logging] + public async Task<APIGatewayProxyResponse> FunctionHandler + (APIGatewayProxyRequest apigProxyEvent, ILambdaContext context) + { + var orderId = apigProxyEvent.PathParameters["orderId"]; + + using (Logger.ExtraKeys(new Dictionary<string, object> { { "orderId", orderId } })) + { + Logger.LogInformation("Processing order"); + await ProcessOrderAsync(orderId); + Logger.LogInformation("Order processed"); // orderId included + } + // orderId is automatically removed + + Logger.LogInformation("Continuing without orderId"); + } + } + + +---|--- + + + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + +| + + + /** + * Handler for requests to Lambda function. + */ + public class Function + { + [Logging] + public async Task<APIGatewayProxyResponse> FunctionHandler + (APIGatewayProxyRequest apigProxyEvent, ILambdaContext context) + { + var orderId = apigProxyEvent.PathParameters["orderId"]; + + using (Logger.ExtraKeys(("orderId", orderId), ("customerId", "customer-123"))) + { + Logger.LogInformation("Processing order"); + await ProcessOrderAsync(orderId); + Logger.LogInformation("Order processed"); // orderId and customerId included + } + // Both keys are automatically removed + } + } + + +---|--- + + + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + +| + + + /** + * Handler for requests to Lambda function. + */ + public class Function + { + [Logging] + public async Task<APIGatewayProxyResponse> FunctionHandler + (APIGatewayProxyRequest apigProxyEvent, ILambdaContext context) + { + using (Logger.ExtraKeys(("requestId", context.AwsRequestId))) + { + Logger.LogInformation("Starting request"); // requestId included + + using (Logger.ExtraKeys(("step", "validation"))) + { + Logger.LogInformation("Validating"); // requestId AND step included + } + // step removed, requestId still present + + Logger.LogInformation("Request complete"); // only requestId + } + } + } + + +---|--- + + + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + +| +