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

fix: Updated Shim to properly calculate the _moduleRoot on windows environments #2014

Merged
merged 1 commit into from Feb 13, 2024

Conversation

bizob2828
Copy link
Member

@bizob2828 bizob2828 commented Feb 12, 2024

Description

This PR simplifies the calculation of this._moduleRoot on shim. Since require-in-the-middle has been introduced it passes us the module root as basedir which gets passed in as resolvedName. The previous logic traversed up directories to find the appropriate root. This logic did not account for windows paths in the regular expression. Instead of fixing that I found this code confusing and unnecessary. For built in packages, the this._moduleRoot will be set as .. this._moduleRoot is only used when calling shim.require which is only done in 3rd party instrumentation so setting builtins to . is really just defensive code.

The only issue I have with this PR is I cannot figure out how to create a failing test for the issue as it only exists on windows and I can't seem to affect path.dirname without using path.win32.dirname but that is not called in shim code.

How to Test

I have a vm that I can standup that shows my PR addresses the issue.

Related Issues

Closes #2012

Copy link

codecov bot commented Feb 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (b460c7b) 97.07% compared to head (c2112ce) 97.07%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2014      +/-   ##
==========================================
- Coverage   97.07%   97.07%   -0.01%     
==========================================
  Files         225      225              
  Lines       40490    40487       -3     
==========================================
- Hits        39307    39304       -3     
  Misses       1183     1183              
Flag Coverage Δ
integration-tests-16.x 78.80% <100.00%> (-0.03%) ⬇️
integration-tests-18.x 79.07% <100.00%> (-0.03%) ⬇️
integration-tests-20.x 79.07% <100.00%> (-0.04%) ⬇️
unit-tests-16.x 91.05% <100.00%> (-0.01%) ⬇️
unit-tests-18.x 91.03% <100.00%> (-0.01%) ⬇️
unit-tests-20.x 91.03% <100.00%> (-0.01%) ⬇️
versioned-tests-16.x 74.63% <100.00%> (-0.03%) ⬇️
versioned-tests-18.x 74.65% <100.00%> (-0.03%) ⬇️
versioned-tests-20.x 74.66% <100.00%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bizob2828 bizob2828 merged commit ab0bd7f into newrelic:main Feb 13, 2024
25 checks passed
Node.js Engineering Board automation moved this from Needs PR Review to Done: Issues recently completed Feb 13, 2024
Copy link
Contributor

@sumitsuthar sumitsuthar left a comment

Choose a reason for hiding this comment

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

module.isBuiltin() API was added in Node.js v16.17.0 What about the versions below v16.17.0?
https://nodejs.org/docs/latest-v16.x/api/module.html#moduleisbuiltinmodulename

@jsumners-nr
Copy link
Contributor

jsumners-nr commented Feb 20, 2024

We support all current LTS releases as described at https://docs.newrelic.com/docs/apm/agents/nodejs-agent/getting-started/compatibility-requirements-nodejs-agent/#system

@bizob2828
Copy link
Member Author

Yea we're a little delayed on dropping 16. This was because it was dropped out of band from their normal LTS schedule

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Node.js Engineering Board
  
Done: Issues recently completed
Development

Successfully merging this pull request may close these issues.

Failed to instrument module @redis/client
3 participants