dd-trace-js
dd-trace-js copied to clipboard
Fix main module loading
What does this PR do?
Fixes module loading when the package defines a folder as their main entrypoint. For, example pg.
Motivation
I tried to use dd-trace-js to send pg traces, but found it didn't work unless I used pg-native. After digging into it, I found that the reason were these lines not accounting for packages that don't define a path to a file.
Additional Notes
- I couldn't find any tests on this functionality but I'm happy to add them if you'd like.
- This only applies if tracing is initiated after the module is loaded (ie: loading from the require cache)
For the tests, this is tested indirectly in the instrumenter tests. Both the express-mock and mysql-mock modules have a main defined while other doesn't. Changing one of them to use a folder would test this.
@rochdev thanks for looking into the PR. I reused the other test.
I'm going to close this PR out as it's pretty old and has some unaddressed issues. Plus, I believe the underlying issue might no longer be applicable as we're able to instrument the pg module as it exists today.
Feel free to reopen / fix any merge conflicts if you'd like it reviewed again!