5

In my config\environments\development.rb and config\environments\production.rb files, I set some global variables. In the example below, I have a a Redis instance that points to our cache, and a Statsd instance that points to the DataDog agent.

config.x.cache = Redis.new(url: ENV["CACHE"])  
config.x.statsd = Statsd.new('localhost', 8125)

In the case of Redis, I added gem 'redis' to my gem file, ran bundle install and everything worked fine. In the case of StatsD, however, it seems that I need to also add require 'statsd' at the top of the development.rb and production.rb files in order to be able to create the instance. Of course, I also added gem 'dogstatsd-ruby' to my gem file and ran bundle install, but that didn't seem to be enough. If I don't add the require statement at the top of the config files, I get the following error when I try to run my Rails app:

uninitialized constant Statsd (NameError)

Can anyone explain why I have to add the require statement only in this particular case (StatsD), or is there is a better way to do this? Thanks!

readyornot
  • 2,783
  • 2
  • 19
  • 31

0 Answers0