-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
feat(node): Local variables via async inspector in node 19+ #9962
feat(node): Local variables via async inspector in node 19+ #9962
Conversation
packages/node/src/integrations/localvariables/localvariables-async.ts
Outdated
Show resolved
Hide resolved
packages/node/src/integrations/localvariables/localvariables-async.ts
Outdated
Show resolved
Hide resolved
packages/node/src/integrations/localvariables/localvariables-async.ts
Outdated
Show resolved
Hide resolved
packages/node/src/integrations/localvariables/localvariables-async.ts
Outdated
Show resolved
Hide resolved
packages/node/src/integrations/localvariables/localvariables-async.ts
Outdated
Show resolved
Hide resolved
packages/node/src/integrations/localvariables/localvariables-async.ts
Outdated
Show resolved
Hide resolved
packages/node/src/integrations/localvariables/localvariables-async.ts
Outdated
Show resolved
Hide resolved
…ctor' into feat/local-variables-async-inspector
@@ -3358,6 +3358,30 @@ declare module 'node:inspector' { | |||
export = inspector; | |||
} | |||
|
|||
/** | |||
* @types/node doesn't have a `node:inspector/promises` module, maybe because it's still experimental? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@types/node
has it, but it is under inspector
. Ref: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/node/inspector.d.ts#L1775
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thats the sync interface with callbacks:
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/a84a09dd3a6ce50a136a7c358c8581f46c812cf1/types/node/inspector.d.ts#L1818
The node:inspector/promises
API returns promises:
https://nodejs.org/api/inspector.html#sessionpostmethod-params
…ctor' into feat/local-variables-async-inspector
aa026a4
to
8db6308
Compare
8db6308
to
a7f98f1
Compare
This PR creates a new `LocalVariables` integration that uses the async inspector API. Rather than create a huge messy integration that supports both the sync (node 18) and async (node >= v19) APIs, I created a new integration and wrapped both the sync and async integrations with user facing integration that switches depending on node version. The async API doesn't require the stacking of callbacks that risks stack overflows and limits the number of frames we dare to evaluate. When we tried wrapping the sync API with promises, memory was leaked at an alarming rate! The inspector APIs are not available on all builds of Node so we have to lazily load it and catch any exceptions. I've had to use `dynamicRequire` because webpack picks up `import()` and reports missing dependency when bundling for older versions of node.
This PR creates a new
LocalVariables
integration that uses the async inspector API.Rather than create a huge messy integration that supports both the sync (node 18) and async (node >= v19) APIs, I created a new integration and wrapped both the sync and async integrations with user facing integration that switches depending on node version.
The async API doesn't require the stacking of callbacks that risks stack overflows and limits the number of frames we dare to evaluate. When we tried wrapping the sync API with promises, memory was leaked at an alarming rate!
The inspector APIs are not available on all builds of Node so we have to lazily load it and catch any exceptions.
For the new integration I usedimport
rather thanrequire
. This async importing, coupled with the async API means that errors that occur before the import and debugger is configured will not have local variables attached... hence the addition of timeouts in the integration tests.I've had to use
dynamicRequire
because webpack picks upimport()
and reports missing dependency when bundling for older versions of node.