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

API to stream things happening on Event Loop #47590

Closed
LRagji opened this issue Apr 17, 2023 · 9 comments
Closed

API to stream things happening on Event Loop #47590

LRagji opened this issue Apr 17, 2023 · 9 comments
Labels
feature request Issues that request new features to be added to Node.js.

Comments

@LRagji
Copy link

LRagji commented Apr 17, 2023

What is the problem this feature will solve?

There are lot of developers who put in console.log just to understand stack trace of the execution. This is a usability problem with most languages, if there was an way in which we could push out all stack frames as they happen on the event loop when lets say a "DEBUG" environment variable is set then most of 90% use cases for writing console.log would be met.. and make debugging even prod applications easy as this is a built in feature of the language.

What is the feature you are proposing to solve the problem?

The feature should be hidden behind a Environment Flag lets say "Debug" when present event loop can start pushing stack frames of completed calls to STDOUT which can be left for the user to capture it.(This informs them about what is executing in the event loop like a peep inside it)

This feature can then be extended by passing in execution time & memory allocated or cleared with function name or stack frames thus telling perf issues if any..

What alternatives have you considered?

  1. Debugger Inspect: This method fail cause you have to keep open extra port on the docker for any exceptions on PROD instances which are normally frowned upon.
  2. https://nodejs.org/api/async_hooks.html: Using this i tried to write my own version of the above feature but its experimental
@LRagji LRagji added the feature request Issues that request new features to be added to Node.js. label Apr 17, 2023
@bnoordhuis
Copy link
Member

Debugger Inspect: This method fail cause you have to keep open extra port on the docker for any exceptions on PROD instances which are normally frowned upon.

No, that's only when you use the command line flags. You can access the inspector programmatically through require('node:inspector'). The building blocks are already in place, you just need to wire it up.

@LRagji
Copy link
Author

LRagji commented Apr 17, 2023

Debugger Inspect: This method fail cause you have to keep open extra port on the docker for any exceptions on PROD instances which are normally frowned upon.

No, that's only when you use the command line flags. You can access the inspector programmatically through require('node:inspector'). The building blocks are already in place, you just need to wire it up.

Ok let me look at node:inspector docs, I also assume it can give me the executing stack without breaking(pausing the debugger)

Tried with debugger api to pause the execution and then resume by collection stack frames "Fails at conceptual level" cause once you pause you pause your own code which cannot resume your debugger, so This option doesn't work,

The native runtime has to support this, and keep publishing the stack-frames on stdout that is the exact ask

@benjamingr
Copy link
Member

The underlying issue is that capturing a stack is expensive as is opening the inspector

@LRagji
Copy link
Author

LRagji commented Apr 18, 2023

There should be some way, cause eventloop does have list of things to do next, it should be able to do dump that (it can be obfuscated, assuming later we merge this dump with some pdb kind of files which can reveal the stack in normal english) again i am not an expert but if we get this done think of how use it can be, run everything as is on prod just capture the logs while issue occurs..

@bnoordhuis
Copy link
Member

Sounds like async_hooks is what you're looking for. Yes, it's experimental. Doesn't mean it's buggy or unusable.

@benjamingr
Copy link
Member

Sounds like async_hooks is what you're looking for

Aren't they being deprecated/removed?

@bnoordhuis
Copy link
Member

Are you referring to #46265? The ETA of that is probably better measured in years than months.

@Flarna
Copy link
Member

Flarna commented Apr 21, 2023

If there are valid usecase for async hooks which can't be replaced by something like AsyncContext, AsyncLocalStore,... it's really unlikely that async hooks get removed. Main target of #46265 and similar discussions is to avoid that people use async hooks for usecases which are better supported by e.g. AsyncLocalStore.

@bnoordhuis
Copy link
Member

In light of @Flarna's comment I'll go ahead and close this. LMK if there's reason to reopen.

@bnoordhuis bnoordhuis closed this as not planned Won't fix, can't repro, duplicate, stale Apr 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Issues that request new features to be added to Node.js.
Projects
Status: Pending Triage
Development

No branches or pull requests

4 participants