-
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
Defer agent initialization in Rails until after :load_config_initializers #1658
Merged
kaylareopelle
merged 9 commits into
dev
from
bugfix/rails-frameworks-forced-to-load-during-agent-initialization
Dec 8, 2022
Merged
Defer agent initialization in Rails until after :load_config_initializers #1658
kaylareopelle
merged 9 commits into
dev
from
bugfix/rails-frameworks-forced-to-load-during-agent-initialization
Dec 8, 2022
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kaylareopelle
changed the title
Instrument ActionView on_load
Defer agent initialization in Rails until after :load_config_initializers
Dec 7, 2022
kaylareopelle
force-pushed
the
bugfix/rails-frameworks-forced-to-load-during-agent-initialization
branch
4 times, most recently
from
December 7, 2022 19:08
249ae16
to
a4e149b
Compare
fallwith
previously approved these changes
Dec 7, 2022
Previously, ActionView was forced to load by the agent before ActiveSupport loaded its code, causing any application-defined initializers related to ActionView to be ignored. Subscribing after ActiveSupport loads ActionView resolves the problem.
The central argument around loading the agent before other initializers is to allow initializers to reference the add_method_tracer API. Including the modules before other initializers are run allows this to happen. If the second initializer doesn't specify when it should be run, it will run immediately after our first initializer. By specifying after: :load_config_initializers, the agent will not execute init_plugin until after initializers defined in config/initializers are run. This stops the agent from forcing ActiveRecord to load before customer-defined initializers.
The previous instructions were not compatible with Zsh. These instructions work with Zsh and bash.
kaylareopelle
force-pushed
the
bugfix/rails-frameworks-forced-to-load-during-agent-initialization
branch
from
December 7, 2022 19:54
a4e149b
to
bbd78a1
Compare
Starting the agent after :load_config_initializers prevents the dynamic initializer for roadie-rails from running, making the gem moot. The customer who used the bugfix also had an error pop up with one of their initializers. Though this change solves the problem with configs getting applied, it may interact unpredictably with existing initializers. We won't turn on this behavior by default until a major version release.
kaylareopelle
commented
Dec 8, 2022
fallwith
reviewed
Dec 8, 2022
kaylareopelle
force-pushed
the
bugfix/rails-frameworks-forced-to-load-during-agent-initialization
branch
from
December 8, 2022 17:59
cb02458
to
7ccc3c5
Compare
fallwith
previously approved these changes
Dec 8, 2022
…-agent-initialization
fallwith
previously approved these changes
Dec 8, 2022
SimpleCov Report
|
fallwith
approved these changes
Dec 8, 2022
kaylareopelle
deleted the
bugfix/rails-frameworks-forced-to-load-during-agent-initialization
branch
December 8, 2022 18:50
kaylareopelle
restored the
bugfix/rails-frameworks-forced-to-load-during-agent-initialization
branch
December 8, 2022 18:58
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
For Rails applications, the agent initialized before all other initializers with the
before: :load_config_initializers
hook.Though this enables initializers to reference the
add_method_tracer
API, there are actions within the agent's initialization that load Rails framework libraries (ActiveJob, ActiveRecord, ActionView). This caused initializers referencing these libraries to be skipped entirely.Since we only need the
add_method_tracer
API to be available before the initializers are run, the modules that include this API will be loaded before config initializers. All other agent-initialization activity will be loaded after config initializers.Furthermore, ActionView was the only Rails framework library that did not have an
ActiveSupport.on_load
block around the instrumentation executes block. This has been added.Closes #662