-
Notifications
You must be signed in to change notification settings - Fork 153
Feature Request: support logging Set
& Map
types
#1649
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
Comments
Thanks for opening your first issue here! We'll come back to you as soon as we can. |
Hi @hfahlbusch thank you for taking the time to open this issue. Before emitting a log the Logger utility calls Like you mentioned I think it could be a good addition to the library so I'm going to change the issue type and mark it as feature request. If there's interest we could definitely add support for those types after agreeing on a format to use. |
Set
type
Yeah, you are right! I guess with the advent of Sets and Maps it would be a good addition. In my opinion it brings some more comfort. I would suggest to convert Set to Array and Map to Object, so it stays valid JSON or are you thinking about "arbitrary" strings to make them distinguishable? |
Set
typeSet
& Map
types
hi @hfahlbusch apologies for the delayed response. The suggestion to convert I think we can approximate and cast most of them to strings, i.e. a I'm putting the issue on the backlog and including it in the scope for the next upcoming major version. I've also edited the type to explicitly include the I'd like to also open the feature for other contributors. If anyone is interested in picking this up, please leave a comment below and let us know if you have any question. If everything is clear, please still leave a comment to let us know you're starting to work on this so we avoid duplicating effort, and if possible also share your comments on the implementation that you'd like to carry out. |
Hi @dreamorosi, maybe I could implement this as a first contribution. Do you have any additional comments to the planned serialization? |
Hi @hfahlbusch thank you for offering your contribution, we'd love to have your contribution! As for additional comments, the only thing to call out would be to start your branch from Other than that I would maybe recommend researching what would be the most appropriate way of coercing I'll assign the issue to you and mark it as work in progress, we can continue the conversation on this last point either in the issue or in the PR if you prefer. If you have any questions on how to setup the dev environment or any other aspect of the project, please let me know - I'll be happy to support. |
Hi @hfahlbusch, just wanted to check in and see if there's anything that I can help with or if you have any questions 😃 |
Hello, We have decided to close this feature in favor of a more powerful implementation that will allow customers to provide their own JSON replacer function. You can find more details in the dedicated issue: #1776 |
|
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
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
The text was updated successfully, but these errors were encountered: