fluent / fluent/fluent-logger-node
JS Date values sent as empty objects
- Dominant language
- JavaScript
- Stars
- 258
- Forks
- 82
- PR merge metrics
- No merged PRs in 30d
Description
Hi guys,
We have noticed that when trying to send a JSON object that contains a field of **Date** instance from the regular **Date** type in Javascript, it is serialized as an empty object. I would expect that the proper behavior should be to convert to ISO Date string.
This is happening due to the fact that fluent-logger is using **msgpack-lite** to encode the objects to be sent. However when a message is encoded it is using a hardcoded codec that is initialized in the instantiation of the module and cannot be accessed externally. See [here](https://github.com/fluent/fluent-logger-node/blob/b6d5934da320dc91af49e2e8e166e19648365c69/lib/sender.js#L12)
So the codec is created without any options, *(skipping even the default codecs because `preset` flag is skipped)* and when the type of the Date value given to serialized is checked with `typeof`, **Object** is returned and an attempt to browse its keys recursively and encode them results to an empty object, since Date instances do not have any browseable keys.
A solution would be to either provide the codec to the instance so it can be configured and extra packers / unpackers could be added, inherited from constructor options from the fluentd logger class, or even just simply enable the default presets of **msgpack-lite** to support JS native data types
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.