Scout Agent Running in Console in Rails 7
mabrikan opened this issue · comments
We faced an issue in which scout agent will start and worker thread will get initialized when running bundle exec rails console
.
I inspected the code that does the checks and I believe that method interactive?
in lib/scout_apm/environment.rb is the one doing so
# If both stdin & stdout are interactive and the Rails::Console constant is defined
def interactive?
defined?(::Rails::Console) && $stdout.isatty && $stdin.isatty
end
I did some debugging and discovered that in later versions of rails (6 or higher) where spring is used to load the app, ::Rails::Console
can become undefined. Of course this causes the method above to return false, hence the agent gets initialized.
I searched for a fix and stumbled upon this thread in another project, but discussing the same issue.
A workaround is to disable spring using export DISABLE_SPRING=true
before running rails console
I just wanted to share this info, also maybe if there is a way to detect if spring is working and add a condition to the method above.
Version info:
ruby '3.2.1'
'rails', '~> 7.0.4.3'
'scout_apm', ''5.3.5'
Hey @mabrikan,
I'm having a hard time recreating this unfortunately:
❯ bundle exec spring rails console
Running via Spring preloader in process 15085
Loading development environment (Rails 7.1.3)
:001 > defined?(::Rails::Console)
=> "constant"
I tried both spring v.4.0.0 and v4.1.3, as well as Rails 6.0.x.
I take it that bouncing spring didn't help at all?