Description
Expected Behaviour
If I enter a Set as a value of the LogItemExtraInput it should print it's elements like the console.log()
and not return {}.
I was thinking there were no data in the set and searched a while for the error.
Current Behaviour
Set with elements will be printed as {}
Code snippet
import { Logger } from '@aws-lambda-powertools/logger';
const log = new Logger({
logLevel: 'DEBUG'
});
const a = new Set();
a.add(1);
a.add(2);
log.debug('My set not logged properly', { data: a});
//{"level":"DEBUG","message":"My set not logged properly","service":"service_undefined","timestamp":"2023-08-12T14:27:00.205Z","data":{}}
console.log('My set logged', a);
// My set logged Set(2) { 1, 2 }
Steps to Reproduce
- Create new node project
- Install powertools logger in node modules
- Copy code snippet from above
- Run and see missing Set data
Possible Solution
I digged a little into the code.
It seems the extra input is stringified with JSON.stringify which cannot handle Sets in the expected way, because the values are not properties of the Set.
Could be added to the getReplacer()
in Logger.js that also handles bigints.
Maybe convert Set to an array [...mySet] or create string representation manually.
Powertools for AWS Lambda (TypeScript) version
latest
AWS Lambda function runtime
18.x
Packaging format used
npm
Execution logs
Example in the logs:
{
"logLevel": "DEBUG",
"message": "Modified products and documents",
"awsRegion": "eu-central-1",
"service": "cache-invalidation",
"timestamp": "2023-08-12T13:43:30.197Z",
"correlationIds": {
"xRayTraceId": "xxxxxxxxxxxxxxxxxxxxxxxx"
},
"durationInMs": 1291,
"changedAfter": "2023-08-09T22:59:56.820Z",
"numberOfProducts": 4,
"numberOfDocuments": 5,
"productIds": [
[
"PROD1",
"sv-se"
],
[
"PROD2",
"no-no"
],
[
"PROD3",
"da-dk"
],
[
"PROD4",
"no-no"
]
],
"documentIds": {}
}
Metadata
Metadata
Assignees
Labels
Type
Projects
Status