Skip to content

PerformanceEntry toJSON() #35936

@spazmodius

Description

@spazmodius

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 Errors). 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    perf_hooksIssues and PRs related to the implementation of the Performance Timing API.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions