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(instrumentation): only call onRequire for full matches on core modules with sub-paths #3451

Merged
merged 7 commits into from
Dec 5, 2022

Conversation

mhassan1
Copy link
Contributor

Which problem is this PR solving?

In #3161, we introduced the RequireInTheMiddleSingleton, which should be a (mostly) drop-in replacement for require-in-the-middle (RITM); however, the way these two handle core modules with sub-paths (e.g. fs/promises) is different. This PR fixes RequireInTheMiddleSingleton to be consistent with RITM.

Fixes #3448

Short description of the changes

Consider the scenario where we are patching a core module (e.g. @opentelemetry/instrumentation-fs, which patches fs). When the application calls require on that core module with a sub-path (e.g. fs/promises), RITM does not see that as internal to fs and thus does not call the onRequire function; however, RequireInTheMiddleSingleton does.

To make RequireInTheMiddleSingleton more consistent with RITM, we should only call the onRequire function for full matches (i.e. fs/promises should call hooks for fs/promises but not for fs).

We detect whether a module is a core module by checking whether basedir is undefined.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

I fixed and added additional unit tests to RequireInTheMiddleSingleton.

Checklist:

  • Followed the style guidelines of this project
  • Unit tests have been added
  • Documentation has been updated

@mhassan1 mhassan1 requested a review from a team November 29, 2022 17:03
@codecov
Copy link

codecov bot commented Nov 29, 2022

Codecov Report

Merging #3451 (bdf3a0d) into main (285f282) will decrease coverage by 1.66%.
The diff coverage is 100.00%.

❗ Current head bdf3a0d differs from pull request most recent head 8905ad0. Consider uploading reports for the commit 8905ad0 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3451      +/-   ##
==========================================
- Coverage   93.75%   92.08%   -1.67%     
==========================================
  Files         248      120     -128     
  Lines        7552     4180    -3372     
  Branches     1576      911     -665     
==========================================
- Hits         7080     3849    -3231     
+ Misses        472      331     -141     
Impacted Files Coverage Δ
...elemetry-instrumentation-grpc/src/grpc-js/index.ts 92.30% <100.00%> (+0.27%) ⬆️
...entelemetry-instrumentation-grpc/src/grpc/index.ts 93.98% <100.00%> (+0.18%) ⬆️
...es/opentelemetry-instrumentation-grpc/src/utils.ts 94.23% <100.00%> (+0.11%) ⬆️
...lemetry-resources/src/detectors/ProcessDetector.ts 31.81% <0.00%> (-68.19%) ⬇️
packages/opentelemetry-sdk-trace-web/src/utils.ts 65.83% <0.00%> (-29.20%) ⬇️
...lemetry-resources/src/detectors/BrowserDetector.ts 93.33% <0.00%> (-6.67%) ⬇️
...nstrumentation/src/platform/node/ModuleNameTrie.ts
...n/src/platform/node/RequireInTheMiddleSingleton.ts
...ental/packages/otlp-transformer/src/trace/types.ts
packages/opentelemetry-propagator-b3/src/common.ts
... and 124 more

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.

@opentelemetry/instrumentation version 0.34.0 breaks @opentelemetry/instrumentation-fs
4 participants