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: Instrument calls to libraries #128

Closed
wants to merge 0 commits into from

Conversation

zermelo-wisen
Copy link
Collaborator

Fixes #83

Copy link
Collaborator

@dividedmind dividedmind left a comment

Choose a reason for hiding this comment

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

I think you're on the right track. Couple of comments:

  • Will this work for ESM? I'm worried the whole approach will need to be different. Unless we can use the same trick for CJS-loading and hoping the hooked module will be cached across the two loaders...
  • The Error approach is a no-go; it will have an unacceptably massive performance hit. Also, it's maybe a bit too complicated; appmap-ruby skips tracing if current_package.shallow? && last_package == current_package (where package is just an appmap.yml package: entry), which is extremely simple and works well in practice. This also allows shallow mode to work for user (eg. path:) packages, a feature occasionally useful.

src/PackageMatcher.ts Outdated Show resolved Hide resolved
@@ -0,0 +1,152 @@
import assert from "node:assert";

import { ESTree } from "meriyah";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please try to use import type when applicable to make it clear when code is being imported vs. just types.

src/requireHook.ts Outdated Show resolved Hide resolved
src/hooks/standardLibs.ts Outdated Show resolved Hide resolved
@dividedmind
Copy link
Collaborator

  • Will this work for ESM? I'm worried the whole approach will need to be different. Unless we can use the same trick for CJS-loading and hoping the hooked module will be cached across the two loaders...

BTW, I think if ESM support is going to be non-trivial it's ok to just do this for CJS for now and open a separate issue to add ESM support later.

@zermelo-wisen zermelo-wisen force-pushed the feat/instrument-calls-to-libraries branch 6 times, most recently from b3e4888 to 970d733 Compare March 29, 2024 07:58
@zermelo-wisen
Copy link
Collaborator Author

  • Will this work for ESM? I'm worried the whole approach will need to be different. Unless we can use the same trick for CJS-loading and hoping the hooked module will be cached across the two loaders...

BTW, I think if ESM support is going to be non-trivial it's ok to just do this for CJS for now and open a separate issue to add ESM support later.

It was trivial for built-ins. For third party libs I managed to do it by implementing resolve function in our custom loader.

@zermelo-wisen zermelo-wisen marked this pull request as ready for review March 29, 2024 12:44
@zermelo-wisen zermelo-wisen force-pushed the feat/instrument-calls-to-libraries branch from 46de9c8 to 988deeb Compare March 30, 2024 10:30
@zermelo-wisen zermelo-wisen force-pushed the feat/instrument-calls-to-libraries branch from 988deeb to 6132680 Compare April 15, 2024 10:16
@zermelo-wisen zermelo-wisen marked this pull request as draft April 16, 2024 07:36
@zermelo-wisen zermelo-wisen force-pushed the feat/instrument-calls-to-libraries branch 2 times, most recently from 1c5375a to b13d2e4 Compare April 16, 2024 08:52
@zermelo-wisen zermelo-wisen marked this pull request as ready for review April 16, 2024 09:01
src/hooks/libraries.ts Outdated Show resolved Hide resolved
src/hooks/libraries.ts Outdated Show resolved Hide resolved
src/recorder.ts Outdated Show resolved Hide resolved
src/recorder.ts Outdated Show resolved Hide resolved
@zermelo-wisen zermelo-wisen force-pushed the feat/instrument-calls-to-libraries branch 5 times, most recently from 6a1f9e5 to 153af06 Compare April 24, 2024 12:55
@zermelo-wisen zermelo-wisen force-pushed the feat/instrument-calls-to-libraries branch from efa6a7b to a8b9fbf Compare August 5, 2024 19:49
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.

Allow instrumenting calls to libraries
2 participants