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

feat(node): Local variables via async inspector in node 19+ #9962

Merged

Conversation

timfish
Copy link
Collaborator

@timfish timfish commented Dec 21, 2023

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 used import rather than require. 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 up import() and reports missing dependency when bundling for older versions of node.

@@ -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?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@timfish timfish marked this pull request as ready for review December 30, 2023 13:48
@timfish timfish changed the title feat(node): Local variables via async inspector in node >= v19 feat(node): Local variables via async inspector in node 19+ Dec 30, 2023
@timfish timfish force-pushed the feat/local-variables-async-inspector branch from aa026a4 to 8db6308 Compare December 30, 2023 14:48
@timfish timfish force-pushed the feat/local-variables-async-inspector branch from 8db6308 to a7f98f1 Compare December 30, 2023 15:01
@AbhiPrasad AbhiPrasad merged commit 1953f2e into getsentry:develop Jan 2, 2024
55 checks passed
@timfish timfish deleted the feat/local-variables-async-inspector branch January 2, 2024 15:01
anonrig pushed a commit that referenced this pull request Jan 3, 2024
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants