-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
Description
Is your feature request related to a problem? Please describe.
My logging logs JSON for object it receives. It can use JSON.stringify
, usually, or a custom serializer (say, for Error
s). To invoke a custom serializer it needs to be able to inspect the object for some arbitrary condition (often instanceof
).
Unfortunately, there seems to be no way to get JSON for a PerformaceEntry
object, and it has no reliably identifying features.
Describe the solution you'd like
Support a toJSON()
function on PerformanceEntry
, as specified.
Describe alternatives you've considered
I could use a custom serializer function, if I had a way to identify the object I have in hand as a PerformanceEntry
. Alas, obj instanceof PerformanceEntry
is impossible because that class is not exposed.
I considered using obj[util.inspect.custom]()
, which is defined on PerformanceNodeTiming
, but not PerformanceEntry
. However, again, I don't know a reliable strategy for deciding when to use it--surely not just whenever it exists.
As a workaround, the client itself has to copy properties explicitly to a POJO. This is brittle and ugly, especially since object-spread is also useless. For exampe, { ...perf_hooks.performance.nodeTiming }
yields an empty object.