JS Date values sent as empty objects
See original GitHub issueHi 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
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
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:9 (9 by maintainers)
Top GitHub Comments
Hmmmm, I understand. I believe that since
Date
could be commonly logged in javascript since it is a native type, it should be logged as ISOString as a generic form at least.This should probably be supported by default but having also available a way to provide some custom packers to the final encoder would be useful for extra customization of the logging serialization format
I think just adding the extra packer as you did above is a good choice. I don’t think the performance overhead is that limiting. Also if we convert it manually, in case of composite data objects, we will have to browse the object in all depths to process all JS Date objects. Also since Date is a Native JS data type, I believe we will find this quite regularly
Currently, the existing solution simply logs dates as empty object, so we have loss of information.
We could also support an extra param in construction of FluendDSreamer so that accepts an extra param with a property, ex: packers that will contain an object of types and their packing / unpacking mechanisms in some kind of convention format.