- 
                Notifications
    You must be signed in to change notification settings 
- Fork 947
          feat(instrumentation): implement require-in-the-middle singleton
          #3161
        
          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
Conversation
| 
 
 | 
| Awesome, this sounds promising, thank you for the PR :)) | 
| Codecov Report
 Additional details and impacted files@@            Coverage Diff             @@
##             main    #3161      +/-   ##
==========================================
+ Coverage   93.44%   93.47%   +0.02%     
==========================================
  Files         241      243       +2     
  Lines        7260     7321      +61     
  Branches     1507     1517      +10     
==========================================
+ Hits         6784     6843      +59     
- Misses        476      478       +2     
 | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love this idea. Very excited for this as its something we've been considering for a while
        
          
                experimental/packages/opentelemetry-instrumentation/src/platform/node/instrumentation.ts
              
                Outdated
          
            Show resolved
            Hide resolved
        
              
          
                experimental/packages/opentelemetry-instrumentation/src/platform/node/instrumentation.ts
          
            Show resolved
            Hide resolved
        
      | How can we progress this PR? I am really interested to speed up the start up of my projects now feels like it takes a few minutes | 
| I am also interested in getting this PR across the finish line. We are receiving more complaints now that we have more and more instrumentations in auto-instrumentations packages (example: #3229 (reply in thread)) | 
        
          
                experimental/packages/opentelemetry-instrumentation/src/platform/node/instrumentation.ts
              
                Outdated
          
            Show resolved
            Hide resolved
        
      | @mhassan1 curious what is required for you to bring this PR into a state ready for review? I have been getting increasing questions about startup cost and this would be a huge win for us. | 
| I've moved it out of Draft. I see some failing checks that I will address now. | 
| Awesome @mhassan1 looking forward trying it out :) | 
| I've cleaned up the PR and added more tests. This is ready for review. | 
| Unit tests are failing. I will look into it. | 
| With this change we are making a hard promise never to change the interface of this because of the global singleton. IMO we should upgrade this to  | 
| @mhassan1 please refrain from modifying history or force pushing. it makes it very difficult to track changes | 
| Unit tests for  | 
| This PR seems to introduce a change in behavior that may not be acceptable without a fix (and this is the reason why the  Assume this scenario: require('http')
new HttpInstrumentation()
require('http')In the  In this PR's code, the singleton RITM will get set up before the first  Is this change in behavior acceptable? It seems like it would be too big of a change to tell users "you must instantiate instrumentation before you  | 
| We already tell users instrumentations must be instantiated first. Your example with  | 
| we even warn if you instantiate an instrumentation for a module that is already in the require cache | 
| Maybe a reasonable solution would be to instantiate RITM only when the first instance of  With that change in place, I see another problem:  What do you think is the right way to resolve that? Is it expected behavior for the user to create multiple instances of  | 
| Disabling instrumentations is mostly meant as a testing feature, but it needs to work. What is happening in the new version that breaks it? Shouldn't we be able to modify the  | 
| I was indeed involved in that PR. It was required in order to instrument aws lambda using a layer. Thanks for the research. Sounds like a huge performance improvement. Did you happen to step through to see if it is possible to work around the issue in the aws lambda or did you just run the test? If we're intercepting all require calls, shouldn't we be able to match on an exact path the same way ritm does? | 
| I don't think there's anything that  I also noticed that RITM passes  | 
| Personally, I think it’s worth it to revisit lambda in the future and merge this PR as it will benefit everyone that’s not using AWS Lambda’s. I can imagine AWS/Amazon can have a closer look at it :) Yes, I am bias as I can’t use AWS in the cases I am using Opentelemetry but do have slow starts (feels to take minutes) when enabling instrumentation  | 
        
          
                experimental/packages/opentelemetry-instrumentation/src/platform/node/ModuleNameTrie.ts
          
            Show resolved
            Hide resolved
        
      | I dismissed my review until I have time to review the updated logic. Don't want this to get merged accidentally before that based on my outdated ✅ | 
| @dyladan Is there anything outstanding that is blocking this PR? | 
| 
 Nothing particular just trying to make sure it's sufficiently reviewed because it's quite fundamental to the instrumentation. I asked more people to review it at the SIG meeting today. | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Requesting changes here so this isn't accidentally merged before @rauno56 comment is addressed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fantastic job, @mhassan1. Thanks for the work and your patience!
Which problem is this PR solving?
This PR changes the behavior of instrumentation plugins to create a single
requirepatch, instead of one per plugin. This should be a significant performance improvement for projects using many instrumentation plugins.Fixes #3029.
Short description of the changes
This PR creates a
require-in-the-middlesingleton that looks for registeredonRequirefunctions for a givenmoduleand executes them.Type of change
How Has This Been Tested?
This PR is mostly covered by existing tests in
InstrumentationBase.test.ts. It adds unit tests for the logic in the_shouldHookfunction.Checklist: