Skip to content
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

Scout Agent Running in Console in Rails 7 #481

Open
mabrikan opened this issue Oct 6, 2023 · 1 comment
Open

Scout Agent Running in Console in Rails 7 #481

mabrikan opened this issue Oct 6, 2023 · 1 comment

Comments

@mabrikan
Copy link

mabrikan commented Oct 6, 2023

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'

@jrothrock
Copy link
Contributor

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants