Skip to content
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

PerformanceEntry toJSON() #35936

Closed
spazmodius opened this issue Nov 3, 2020 · 2 comments
Closed

PerformanceEntry toJSON() #35936

spazmodius opened this issue Nov 3, 2020 · 2 comments
Labels
perf_hooks Issues and PRs related to the implementation of the Performance Timing API.

Comments

@spazmodius
Copy link

spazmodius commented Nov 3, 2020

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.

@mmomtchev
Copy link
Contributor

@spazmodius, I agree that there is no PerformanceEntry.toJSON() function as specified, but JSON.stringify() works perfectly for PerformanceEntry. It doesn't work for PerformanceNodeTiming, is this what you mean?

@targos targos added the perf_hooks Issues and PRs related to the implementation of the Performance Timing API. label Nov 5, 2020
mmomtchev added a commit to mmomtchev/node that referenced this issue Nov 5, 2020
Render all properties of nodeTiming enumerable
so JSON.stringify and Object.keys can access them

Fixes: nodejs#35936
@spazmodius
Copy link
Author

doesn't work for PerformanceNodeTiming

Yes, that's my reference point. I didn't realize the other subtypes will jsonify.

@aduh95 aduh95 closed this as completed in feff385 Nov 14, 2020
codebytere pushed a commit that referenced this issue Nov 22, 2020
Render all properties of nodeTiming enumerable
so JSON.stringify and Object.keys can access them

Fixes: #35936

PR-URL: #35977
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
targos pushed a commit that referenced this issue May 1, 2021
Render all properties of nodeTiming enumerable
so JSON.stringify and Object.keys can access them

Fixes: #35936

PR-URL: #35977
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
perf_hooks Issues and PRs related to the implementation of the Performance Timing API.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants