Skip to content

Feature Request: support logging Set & Map types #1649

Closed as not planned
Closed as not planned
@hfahlbusch

Description

@hfahlbusch

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

  1. Create new node project
  2. Install powertools logger in node modules
  3. Copy code snippet from above
  4. 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

feature-requestThis item refers to a feature request for an existing or new utilityloggerThis item relates to the Logger UtilityrejectedThis is something we will not be working on. At least, not in the measurable future

Type

No type

Projects

Status

Closed

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions