-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: Logging casing affects nested object properties #417
Comments
@sliedig update on this, other runtimes are only changing the casing on powertools added properties, so we can do your solution 1 but only for powertools properties. |
Team decision log
|
With the proposed update, will the output logging represent example 1 or 2 when the output logging is set to Logging Input Logger.LogInformation(new
{
topic = "Requesting new order.",
uriPart,
CreateOrderRequest = req,
RequestJson = http.json,
client.DefaultRequestHeaders
}); Output Example 1 {
"cold_start": true,
"xray_trace_id": "1-64f2e834-b9df67f7a705145c59f8092f",
"function_name": "my-function",
"function_version": "$LATEST",
"function_memory_size": 512,
"name": "AWS.Lambda.Powertools.Logging.Logger",
"message": {
"topic": "Requesting new order.",
"uriPart": "/foo/bar/orders",
"CreateOrderRequest": {
"SourceKey": "3d7432696a88a9ff201b356d5ff4f058",
"SourceType": "customer"
},
"RequestJson": "{ some json }",
"DefaultRequestHeaders": [
"key": "value"
]
}
} Output Example 2 {
"cold_start": true,
"xray_trace_id": "1-64f2e834-b9df67f7a705145c59f8092f",
"function_name": "my-function",
"function_version": "$LATEST",
"function_memory_size": 512,
"name": "AWS.Lambda.Powertools.Logging.Logger",
"message": {
"topic": "Requesting new order.",
"uri_part": "/foo/bar/orders",
"create_order_request": {
"source_key": "3d7432696a88a9ff201b356d5ff4f058",
"source_type": "customer"
},
"request_json": "{ some json }",
"default_request_headers": [
"key": "value"
]
}
} |
@nCubed from my understanding, the message will not be affected by the casing defined in Powertools, so it would be as shown in your output example 1. |
@hjgraca - If the output will be like Example 1, then this would be a major breaking change in the current behavior. I would strongly encourage this behavior not be changed by default. How about allowing consumers to "opt-out" of having the message property being included? This would maintain current behavior and allow consumers to decide if they really want the message property to be excluded. |
@nCubed thank you for your feedback. PS: in terms of comparison with other runtimes, .NET is the only one that allows for case configuration, which is something that is good and bad, so something to consider here as well to just have all runtimes with the same case. again up for discussion. |
This is now possible with version 2 of Logging which now supports JsonSerializerOptions We kept the existing behaviour the same for backwards compatibility. builder.Logging.AddPowertoolsLogger(options =>
{
options.JsonOptions = new JsonSerializerOptions
{
DictionaryKeyPolicy = null // Override output casing
};
}); |
Expected Behaviour
Logger should respect the casing of the of the object it logs, irrespective of the
POWERTOOLS_LOGGER_CASE
configuration. In the following example, the logging attribute logs the Amazon.Lambda.SQSEvents.SQSEvent. In this instance thePOWERTOOLS_LOGGER_CASE
setting is not defined and defaults to snake case (the current default setting, see docs).The log output should be.
Current Behaviour
By default, if you apply the above example, the output would look like this - everything snake case.
Similarly, if you define
POWERTOOLS_LOGGER_CASE
as camel case, you get:In both cases, this is a misrepresentation of the definition of the SQSEvent class.
Code snippet
Possible Solution
Two recommendations:
Do not apply key casing conventions to nested objects. Keep the property definition of the original object. Apply casing configuration to top-level keys only. This includes all extra keys, but not the values of the extra keys.
Make Pascal case the default casing for all keys. This is the default casing for .NET and should be an opt-out if users want something different, rather than it being an opt in.
Steps to Reproduce
Do nothing. Or change the
POWERTOOLS_LOGGER_CASE
to CamelCasePowertools for AWS Lambda (.NET) version
latest
AWS Lambda function runtime
dotnet6
Debugging logs
No response
The text was updated successfully, but these errors were encountered: