-
Notifications
You must be signed in to change notification settings - Fork 375
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
Autoloading in Rails initializer #2709
Comments
👋 @oskarpearson , Thanks for sharing this. I think it make sense However, I would like learn more about the trouble of our current implementation with Rails 7 autoloading. Is it broken in some ways we overlooked? or it is working as expected but having some kind of bad developer experience? Could you provide me a bit more description about the current behaviour and what is causing trouble? So that I can search through the project to see with there are issues with similar patterns. |
For us the application fails to boot with a NameError uninitialized constant ErrorsController. |
@TonyCTHsu Thanks for the followup here The breakage is that using the suggested
For more detail, see You can replicate this easily - build a new Rails 7 application, add datadog to it, add an ErrorsController class, and then add a config as follows:
On Rails 7 it will refuse to boot, and you will receive the error:
|
I suggest allowing a fully qualified class name String to be provided in the |
What's the next step here @TonyCTHsu and @marcotc ? |
Is your feature request related to a problem? Please describe.
In Rails 7 autoloading is disabled when an application boots. So things in the
config/initalizers
folder don't support autoloading.However, the Datadog dd-trace-rb gem Rails integration takes a
exception_controller
parameter which needs to point at the class. Something like this:To use this, we need to jump through some hoops - like wrapping the whole of the datadog initialisation in
Rails.application.reloader.to_prepare do
(which I expect won't work anyway?), or theconfig.autoload_once_paths
Rails feature. Using the latter (as I read it) means we can't autoload code when ErrorsController loads.Describe the goal of the feature
I'd like to be able to pass a Symbol or string as the
exception_controller
parameter, rather than the actual class.So the Datadog config would change to something like
c.tracing.instrument :rails, exception_controller: :ErrorsController
or potentiallyc.tracing.instrument :rails, exception_controller: "ErrorsController"
Describe alternatives you've considered
None
Additional context
https://github.com/DataDog/dd-trace-rb/blob/cb6f3a4ed44d41719570ed30ae8da19dd1f73c51/lib/datadog/tracing/contrib/action_pack/action_controller/instrumentation.rb would need to try and use
constantize
of the supplied parameter (currently it just returns false if it's not a class or module)How does
ddtrace
help you?N/A
The text was updated successfully, but these errors were encountered: