-
Notifications
You must be signed in to change notification settings - Fork 161
Closed
Labels
bugSomething isn't workingSomething isn't workingcompletedThis item is complete and has been merged/shippedThis item is complete and has been merged/shippedgood-first-issueSomething that is suitable for those who want to start contributingSomething that is suitable for those who want to start contributingloggerThis item relates to the Logger UtilityThis item relates to the Logger Utility
Milestone
Description
Bug description
As described in the docs Logger
accepts a second parameter that allows to append additional keys and values in a single log item.
This works when passing an object, for example logger.info('my-message', { data: 'my-value' });
results in:
{
"cold_start": true,
"function_arn": "arn:aws:lambda:eu-west-1:123456789101:function:myFunction",
"function_memory_size": 128,
"function_name": "AwsLambdaPowertoolsDemoSt-HelloWorldFunctionB2AB6E-sYstm6IvDAEB",
"function_request_id": "b5fe0e01-91f5-43f2-8ef9-d572df88b61c",
"level": "INFO",
"message": "my-message",
"service": "service_undefined",
"timestamp": "2022-02-21T11:15:18.493Z",
"data": "my-value"
}
But when passing directly a string, like: logger.info('my-message', 'my-value');
it results in this:
{
"0": "m",
"1": "y",
"2": "-",
"3": "v",
"4": "a",
"5": "l",
"6": "u",
"7": "e",
"cold_start": false,
"function_arn": "arn:aws:lambda:eu-west-1:123456789101:function:myFunction",
"function_memory_size": 128,
"function_name": "AwsLambdaPowertoolsDemoSt-HelloWorldFunctionB2AB6E-sYstm6IvDAEB",
"function_request_id": "a0c5ab8f-c0f0-40fa-8c75-347020065880",
"level": "INFO",
"message": "my-message",
"service": "service_undefined",
"timestamp": "2022-02-21T11:08:19.611Z"
}
Likewise, when passing an array, logger.info('my-message', ['my-value', 'my-value2']);
it results in:
{
"0": "my-value",
"1": "my-value2",
"cold_start": true,
"function_arn": "arn:aws:lambda:eu-west-1:123456789101:function:myFunction",
"function_memory_size": 128,
"function_name": "AwsLambdaPowertoolsDemoSt-HelloWorldFunctionB2AB6E-sYstm6IvDAEB",
"function_request_id": "b5fe0e01-91f5-43f2-8ef9-d572df88b61c",
"level": "INFO",
"message": "my-message",
"service": "service_undefined",
"timestamp": "2022-02-21T11:15:18.493Z",
}
Expected Behavior
Have a consistent behaviour across data types, potentially using a default key when a string or array are passed, i.e. logger.info('my-message', 'my-value');
{
"extra_data": "my-value",
"cold_start": false,
"function_arn": "arn:aws:lambda:eu-west-1:123456789101:function:myFunction",
"function_memory_size": 128,
"function_name": "AwsLambdaPowertoolsDemoSt-HelloWorldFunctionB2AB6E-sYstm6IvDAEB",
"function_request_id": "a0c5ab8f-c0f0-40fa-8c75-347020065880",
"level": "INFO",
"message": "my-message",
"service": "service_undefined",
"timestamp": "2022-02-21T11:08:19.611Z"
}
Current Behavior
{
"0": "m",
"1": "y",
"2": "-",
"3": "v",
"4": "a",
"5": "l",
"6": "u",
"7": "e",
"cold_start": false,
"function_arn": "arn:aws:lambda:eu-west-1:123456789101:function:myFunction",
"function_memory_size": 128,
"function_name": "AwsLambdaPowertoolsDemoSt-HelloWorldFunctionB2AB6E-sYstm6IvDAEB",
"function_request_id": "a0c5ab8f-c0f0-40fa-8c75-347020065880",
"level": "INFO",
"message": "my-message",
"service": "service_undefined",
"timestamp": "2022-02-21T11:08:19.611Z"
}
Expand below to see full CloudWatch log output
```log
2022-02-21T11:08:19.611Z a0c5ab8f-c0f0-40fa-8c75-347020065880 INFO {"0":"m","1":"y","2":"-","3":"v","4":"a","5":"l","6":"u","7":"e","cold_start":false,"function_arn":"arn:aws:lambda:eu-west-1:123456789101:function:AwsLambdaPowertoolsDemoSt-HelloWorldFunctionB2AB6E-sYstm6IvDAEB","function_memory_size":128,"function_name":"AwsLambdaPowertoolsDemoSt-HelloWorldFunctionB2AB6E-sYstm6IvDAEB","function_request_id":"a0c5ab8f-c0f0-40fa-8c75-347020065880","level":"INFO","message":"my-key","service":"service_undefined","timestamp":"2022-02-21T11:08:19.611Z"}
```
Possible Solution
Check data types and treat them accordingly.
Steps to Reproduce
- Use any version of
@aws-lambda-powertools/logger
in your Lambda - Emit a lot entry and pass a string or array as second parameter
- Check logs
Environment
- Powertools version used: any
- Packaging format (Layers, npm): N/A
- AWS Lambda function runtime: nodejs14.x
- Debugging logs: (see above)
Related issues, RFCs
N/A
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingcompletedThis item is complete and has been merged/shippedThis item is complete and has been merged/shippedgood-first-issueSomething that is suitable for those who want to start contributingSomething that is suitable for those who want to start contributingloggerThis item relates to the Logger UtilityThis item relates to the Logger Utility