-
Notifications
You must be signed in to change notification settings - Fork 601
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
RPM forces Rails frameworks to load during initialization #662
Comments
Hello @jdelStrother, thank you for submitting this issue. A question to clarify, is this behavior observed with a particular version of the ruby agent? |
Hi there - I'm seeing it in 7.0.0. |
Any updates on this? |
Hello @jdelStrother, this is was placed in our next bugsmash, so we will be taking a closer look at this issue when we start work on that milestone. At that time we will look into potential options to address your concerns and decide how we want the agent to handle these scenarios. |
@jdelStrother (Note I deleted my previous responses since I misunderstood the problem originally) I want to make a note for our team on why this is happening:
As also mentioned, moving
I don't yet have a solution for ActiveRecord/ActiveJob (other than another large refactoring of method tracers), but there are a couple workarounds:
I will get a PR up for at least one of these shortly. |
#806 was planned to be included in the upcoming release; however, during the release process we uncovered an issue involving initialization load order with a specific gem (roadie-rails in this case). Pending determination of the scope of this problem and whether a fix will require breaking changes to the agent, we are reverting #806 for the release of Ruby Agent 8.1.0. We apologize for any inconvenience. |
Hi @jdelStrother, thanks for the feedback! Given there's a chance the initialization change may interfere with existing initializers, we decided to place the fix inside a configuration option, In 8.14.0 (and if you're using the branch on its latest commit), |
Thanks, will try it out once 8.14 is out |
Hi @jdelStrother, version 8.14.0 of the |
Ugh, sorry - I don't think this fix works. By this point - newrelic-ruby-agent/lib/newrelic_rpm.rb Line 23 in fec78e8
|
@jdelStrother, you so right. I deeply apologize for this oversight. Thank you for giving us a heads up. Looking back, I ran my final tests on an earlier version of the bugfix branch, not the one with the config. 🤦♀️ Our team will need to sort out the best response to get this fix into a release. In the meantime, I've updated the We'll be back soon with more information. Code snippet to use this branch if anyone needs it. Replace the gem 'newrelic_rpm', git: 'https://github.com/newrelic/newrelic-ruby-agent.git', branch: 'bugfix/rails-frameworks-forced-to-load-during-agent-initialization' |
Work has been completed on this issue. |
Hi @jdelStrother, we have a branch ready for testing that enables this feature using an environment variable instead of a YAML-based config. The branch is called To use the split initialization process, set |
Looks good from the initialization-order point of view, though I did have to add |
@jdelStrother Interesting, I suspect it's because we have a check in our net http instrumentation that will install chain if rack mini profiler is defined, because it uses method chaining. Perhaps because of the change in when the agent is installing instrumentation now, |
closed by PR #1791 |
Description
Loading the newrelic gem causes ActionView::Base, ActiveRecord::Base & ActiveJob::Base to load before config-initialization. Normally this should be deferred to after_initialize.
One particular example: Rails generates a
config/initializers/new_framework_defaults_6_1.rb
file which configures ActiveRecord settings (egRails.application.config.active_record.has_many_inversing = true
). However, if ActiveRecord::Base has already loaded, this config has no effect, and any changes to it are silently ignored.Expected Behavior
ActionView::Base, ActiveRecord::Base & ActiveJob::Base aren't loaded until after config/initializers are processed.
Here's the stack where ActiveRecord is loaded:
And for ActionView:
The ActionView one is pretty easy to fix, I think it just needs something like this: jdelStrother@d6d046e
ActiveRecord looks harder, it seems pretty tied into the Agent::DatabaseAdapter bits from a casual glance. One option would be to defer loading of the entire agent until after
:load_config_initializers
(essentially reverting #279), but that does seem like it causes problems with adding method_tracers during initialization. Maybe add_method_tracer could be updated to not require a live agent? Or everyone could wrap their add_method_tracer calls in Rails.application.config.after_initialize blocks 😕The text was updated successfully, but these errors were encountered: