Error with new Rails gem "agent_ruby"

I am migrating to the new ruby gem “agent_ruby” for my rails app.

Failure Logs

I have the following error when loading the dashboard:

NameError (uninitialized constant ForestAdminRails::ForestController::OpenIDConnect):

Causes:

ForestAdminAgent::Error (Cannot retrieve the data from the Forest server. An error occured in Forest API)

NoMethodError (undefined method ‘’ for nil)

forest_admin_rails (1.0.0.pre.beta.102) app/controllers/forest_admin_rails/forest_controller.rb:42:in ‘ForestAdminRails::ForestController#exception_handler’

Context

  • Project name: lalanguefrancaise
  • Team name: lalanguefrancaise
  • Environment name: development
  • Database type: postgresql
  • Recent changes made on your end if any: NA

Forest initializer:

ForestAdminRails.configure do |config|
  config.auth_secret = 'xxx'
  config.env_secret = 'FOREST_ENV_SECRET'
end

Forest create_agent.rb:

module ForestAdminRails
  class CreateAgent
    def self.setup!
      database_configuration = Rails.configuration.database_configuration
      datasource = ForestAdminDatasourceActiveRecord::Datasource.new(database_configuration[Rails.env])

      @create_agent = ForestAdminAgent::Builder::AgentFactory.instance.add_datasource(datasource)
      customize
      @create_agent.build
    end
…
1 Like

Hello @nico_lrx

Appreciate you testing the Ruby agent beta! :raising_hands:
It looks like the error you’re encountering is due to a missing openid_connect gem, which is required internally by the agent for authentication purposes.

To check whether this gem is properly installed in your project, you can run the following command

bundle show openid_connect

If the gem is not found, it’s likely because only forest_admin_rails was added to your Gemfile. However, this gem doesn’t include all required dependencies by itself.

To install the full Ruby agent properly, please make sure to add all the following gems:

gem "forest_admin_rails", "~> 1.0.0.pre.beta"
gem "forest_admin_agent", "~> 1.0.0.pre.beta"
gem "forest_admin_datasource_toolkit", "~> 1.0.0.pre.beta"
gem "forest_admin_datasource_active_record", "~> 1.0.0.pre.beta"
gem "forest_admin_datasource_customizer", "~> 1.0.0.pre.beta"

You can also follow our full installation guide here:

Hope that helps, feel free to reach out if you hit another issue!

openid_connect is installed:
/Users/xxx/.rvm/gems/ruby-3.4.4/gems/openid_connect-2.3.1

I have the same gem:

Gemfile.lock:

forest_admin_agent (1.0.0.pre.beta.102)
  activesupport (>= 6.1)
  deepsort (~> 0.4.5)
  dry-container (~> 0.11)
  faraday (~> 2.7)
  filecache (~> 1.0)
  ipaddress (~> 0.8.3)
  jsonapi-serializers (~> 1.0)
  jwt (~> 2.7)
  ld-eventsource (~> 2.2)
  mono_logger (~> 1.1)
  openid_connect (~> 2.2)
  rack-cors (~> 2.0)
  rake (~> 13.0)
  zeitwerk (~> 2.3)
forest_admin_datasource_active_record (1.0.0.pre.beta.102)
  activerecord (>= 6.1)
  activesupport (>= 6.1)
  zeitwerk (~> 2.3)
forest_admin_datasource_customizer (1.0.0.pre.beta.102)
  activesupport (>= 6.1)
  marcel (~> 1.0, >= 1.0.4)
  zeitwerk (~> 2.3)
forest_admin_datasource_toolkit (1.0.0.pre.beta.102)
  activesupport (>= 6.1)
  zeitwerk (~> 2.3)
forest_admin_rails (1.0.0.pre.beta.102)
  dry-configurable (~> 1.1)
  rails (>= 6.1)
  zeitwerk (~> 2.3)

Since the gem was correctly installed, the issue came from how the OpenIDConnect constant is loaded. In some setups (depending on the loading order and environment), it may not be automatically available when the controller is loaded.

We’ve fixed this on our side by explicitly requiring the gem at the top of the forest_controller.rb file.

The patch has been released in version v1.0.0-beta.104 — you can update to that version to resolve the issue.

Thanks again for reporting this! :folded_hands:

Thanks @matthv. I upgraded the gem but now I get the following errors when trying to load the dashboard:

../gems/ruby-3.4.4/gems/forest_admin_rails-1.0.0.pre.beta.104/app/controllers/forest_admin_rails/forest_controller.rb:54:in ‘ForestAdminRails::ForestController#exception_handler’: undefined method ‘name’ for an instance of ForestAdminAgent::Error (NoMethodError)

name: exception.name,

../gems/ruby-3.4.4/gems/forest_admin_agent-1.0.0.pre.beta.104/lib/forest_admin_agent/services/ip_whitelist.rb:96:in ‘ForestAdminAgent::Services::IpWhitelist#fetch_rules’: Cannot retrieve the data from the Forest server. An error occured in Forest API (ForestAdminAgent::Error)

It looks like we’re hitting a similar issue as before, this time with how the ForestAdminAgent::Error class is used. A patch is currently in progress to address this.

The issue related to IpWhitelist is usually caused by a misconfiguration of the ‘FOREST_ENV_SECRET’ variable, could you please double check the value present inside of your config.env_secret and also share with me the last 4 chars of your secret ?
you should have executed the command using the FOREST_ENV_SECRET defined inside your previous agent
rails g forest_admin_rails:install [FOREST_ENV_SECRET]

I double-checked and the FOREST_ENV_SECRET variable matches the one in my dashboard, in the development environment. Here are the last 4 chars: 59cb

Thanks.

We’ve just released version v1.0.0-beta.106 of the agent, which includes additional logs to help debug issues related to the IP whitelist feature.

I’ve checked on our side, and so far we we didn’t receive any call containing your env secret.

Would you mind updating to the latest version and trying again (in debug mode)? That should help us move forward more easily.

I upgraded but still get the error about the IP whitelist feature:

DEBUG – : {error: “undefined method ‘’ for nil”, status: 404, response: “{"errors":[{"status":404,"detail":"Not found error","name":"NotFoundError"}]}”}

D, [2025-06-13T11:39:29.920638 #4644] DEBUG – : /Users/xxx/.rvm/gems/ruby-3.4.4/gems/forest_admin_agent-1.0.0.pre.beta.106/lib/forest_admin_agent/services/ip_whitelist.rb:101:in ‘ForestAdminAgent::Services::IpWhitelist#fetch_rules’: Cannot retrieve the data from the Forest server. An error occured in Forest API (ForestAdminAgent::Error)

/.rvm/gems/ruby-3.4.4/gems/forest_admin_agent-1.0.0.pre.beta.106/lib/forest_admin_agent/services/ip_whitelist.rb:91:in ‘ForestAdminAgent::Services::IpWhitelist#fetch_rules’: undefined method ‘[]’ for nil (NoMethodError)

ip_whitelist_data = body[‘data’][‘attributes’]

Note that I haven’t configured any ip_whitelist in the dashboard. I just have the following config in config/application.rb (I tried to remove it but same errors):

# ForestAdmin CORS configuration
    null_regex = Regexp.new(/\Anull\z/)
    config.middleware.insert_before 0, Rack::Cors do
      allow do
        hostnames = [null_regex, 'localhost:4200', 'app.forestadmin.com', 'localhost:3001']
        hostnames += ENV['CORS_ORIGINS'].split(',') if ENV['CORS_ORIGINS']
        origins hostnames
        resource '*',
          headers: :any,
          methods: :any,
          expose: ['Content-Disposition'],
          credentials: true
      end
    end

The 404 response is unexpected, the IP whitelist endpoint should normally be reachable.

To help us investigate, could you open your Rails console and run ForestAdminRails.config?

Then, please send me the result in a private message.

From what you shared, the value of your env_secret doesn’t look correct, your secret key isn’t being properly registered.

Can you double-check that you don’t have a duplicate configuration file under config/initializers that might override the correct one?

Also, it might help to clear your Rails cache by running:
bin/rails tmp:cache:clear

Once you’ve done that, you can confirm everything is loaded properly by running ForestAdminRails.config in your rails console.

1 Like

Thanks, that did the trick. The config/initializer wasn’t properly registering the env_secret!

That did the trick, but I’m still getting errors in the Dashboard. It seems Forest doesn’t recognize my collections.

NoMethodError (undefined method ‘name’ for an instance of ForestAdminDatasourceToolkit::Exceptions::ForestException):

Causes:

ForestAdminDatasourceToolkit::Exceptions::ForestException (:deciduous_tree::deciduous_tree::deciduous_tree: Collection Word not found.)

Thanks for the update!

Would you mind sharing the code of your Word model so we can take a closer look? That should help us understand what’s going wrong.
Also, can you confirm the name of the corresponding table in your database?

It doesn’t seem to be directly related to your Word model, but more likely to a customization issue in your agent setup.

Could you try commenting out the customize call inside the self.setup! method in the app/lib/forest_admin_rails/create_agent.rb file (or the entire self.customize method)?

There might be a typo or an unexpected error in your customization that’s preventing the agent from initializing properly.

Let us know what happens once that’s done!

1 Like

Indeed, that worked! I still have a few custom charts that are not rendered, but I need to check my code to configure them properly. Thanks!

1 Like

@matthv, it seems the requests are not built properly for some charts:

Eg.

Error:

PG::GroupingError (ERROR:  column "comments.created_at" must appear in the GROUP BY clause or be used in an aggregate function
LINE 1: SELECT DATE_TRUNC('day', created_at) AS "created_at", count(...
                                 ^
)

I uncommented the “customize” section in create_agent.rb, so I guess the issue is from the gem’s code.

I’ve been able to reproduce the error on my side as well. I’m currently working on a fix and will get back to you very shortly with a patch.

Thank you for your patience!