Adding gem dependency in environment-specific file does not work
I tried only adding newrelic_rpm as a gem dependecy to the production environment (didn't want it loaded in development) and got obscure errors: Uninitialized Constant: NewRelic::Agent
that occured when adding "config.gem 'newrelic_rpm', :version => '>=2.8.1'" to my production.rb
it ran fine when adding the same line to environment.rb
backtrace:
> rake production db:charset --trace >> ~/Desktop/backtrace.txt
DEPRECATION WARNING: The fragment_cache_store= method is now use cache_store= See http://www.rubyonrails.org/deprecation for details. (called from fragment_cache_store= at /Library/Ruby/Gems/1.8/gems/actionpack-2.1.2/lib/action_controller/caching/fragments.rb:33)
rake aborted!
uninitialized constant NewRelic::Agent
/Library/Ruby/Gems/1.8/gems/activesupport-2.1.2/lib/active_support/dependencies.rb:276:in `load_missing_constant'
/Library/Ruby/Gems/1.8/gems/activesupport-2.1.2/lib/active_support/dependencies.rb:468:in `const_missing'
/Library/Ruby/Gems/1.8/gems/newrelic_rpm-2.8.1/lib/new_relic/config.rb:190:in `start_agent'
/Library/Ruby/Gems/1.8/gems/newrelic_rpm-2.8.1/lib/new_relic/config/rails.rb:25:in `start_plugin'
/Library/Ruby/Gems/1.8/gems/newrelic_rpm-2.8.1/lib/newrelic_rpm.rb:22
/Library/Ruby/Gems/1.8/gems/rails-2.1.2/lib/initializer.rb:476:in `call'
/Library/Ruby/Gems/1.8/gems/rails-2.1.2/lib/initializer.rb:476:in `after_initialize'
/Library/Ruby/Gems/1.8/gems/rails-2.1.2/lib/initializer.rb:475:in `each'
/Library/Ruby/Gems/1.8/gems/rails-2.1.2/lib/initializer.rb:475:in `after_initialize'
/Library/Ruby/Gems/1.8/gems/rails-2.1.2/lib/initializer.rb:152:in `process'
/Library/Ruby/Gems/1.8/gems/rails-2.1.2/lib/initializer.rb:97:in `send'
/Library/Ruby/Gems/1.8/gems/rails-2.1.2/lib/initializer.rb:97:in `run'
/Users/gerrit/Development/trike/pedia/config/environment.rb:13
/Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
/Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require'
/Library/Ruby/Gems/1.8/gems/activesupport-2.1.2/lib/active_support/dependencies.rb:510:in `require'
/Library/Ruby/Gems/1.8/gems/activesupport-2.1.2/lib/active_support/dependencies.rb:355:in `new_constants_in'
/Library/Ruby/Gems/1.8/gems/activesupport-2.1.2/lib/active_support/dependencies.rb:510:in `require'
/Library/Ruby/Gems/1.8/gems/rails-2.1.2/lib/tasks/misc.rake:3
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:617:in `call'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:617:in `execute'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:612:in `each'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:612:in `execute'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:578:in `invoke_with_call_chain'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:571:in `invoke_with_call_chain'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:588:in `invoke_prerequisites'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:585:in `each'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:585:in `invoke_prerequisites'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:577:in `invoke_with_call_chain'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:571:in `invoke_with_call_chain'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:564:in `invoke'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:2019:in `invoke_task'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:1997:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:1997:in `each'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:1997:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:2036:in `standard_exception_handling'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:1991:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:1970:in `run'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:2036:in `standard_exception_handling'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:1967:in `run'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/bin/rake:31
/usr/bin/rake:19:in `load'
/usr/bin/rake:19
that occured when adding "config.gem 'newrelic_rpm', :version => '>=2.8.1'" to my production.rb
it ran fine when adding the same line to environment.rb
backtrace:
> rake production db:charset --trace >> ~/Desktop/backtrace.txt
DEPRECATION WARNING: The fragment_cache_store= method is now use cache_store= See http://www.rubyonrails.org/deprecation for details. (called from fragment_cache_store= at /Library/Ruby/Gems/1.8/gems/actionpack-2.1.2/lib/action_controller/caching/fragments.rb:33)
rake aborted!
uninitialized constant NewRelic::Agent
/Library/Ruby/Gems/1.8/gems/activesupport-2.1.2/lib/active_support/dependencies.rb:276:in `load_missing_constant'
/Library/Ruby/Gems/1.8/gems/activesupport-2.1.2/lib/active_support/dependencies.rb:468:in `const_missing'
/Library/Ruby/Gems/1.8/gems/newrelic_rpm-2.8.1/lib/new_relic/config.rb:190:in `start_agent'
/Library/Ruby/Gems/1.8/gems/newrelic_rpm-2.8.1/lib/new_relic/config/rails.rb:25:in `start_plugin'
/Library/Ruby/Gems/1.8/gems/newrelic_rpm-2.8.1/lib/newrelic_rpm.rb:22
/Library/Ruby/Gems/1.8/gems/rails-2.1.2/lib/initializer.rb:476:in `call'
/Library/Ruby/Gems/1.8/gems/rails-2.1.2/lib/initializer.rb:476:in `after_initialize'
/Library/Ruby/Gems/1.8/gems/rails-2.1.2/lib/initializer.rb:475:in `each'
/Library/Ruby/Gems/1.8/gems/rails-2.1.2/lib/initializer.rb:475:in `after_initialize'
/Library/Ruby/Gems/1.8/gems/rails-2.1.2/lib/initializer.rb:152:in `process'
/Library/Ruby/Gems/1.8/gems/rails-2.1.2/lib/initializer.rb:97:in `send'
/Library/Ruby/Gems/1.8/gems/rails-2.1.2/lib/initializer.rb:97:in `run'
/Users/gerrit/Development/trike/pedia/config/environment.rb:13
/Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
/Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require'
/Library/Ruby/Gems/1.8/gems/activesupport-2.1.2/lib/active_support/dependencies.rb:510:in `require'
/Library/Ruby/Gems/1.8/gems/activesupport-2.1.2/lib/active_support/dependencies.rb:355:in `new_constants_in'
/Library/Ruby/Gems/1.8/gems/activesupport-2.1.2/lib/active_support/dependencies.rb:510:in `require'
/Library/Ruby/Gems/1.8/gems/rails-2.1.2/lib/tasks/misc.rake:3
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:617:in `call'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:617:in `execute'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:612:in `each'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:612:in `execute'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:578:in `invoke_with_call_chain'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:571:in `invoke_with_call_chain'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:588:in `invoke_prerequisites'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:585:in `each'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:585:in `invoke_prerequisites'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:577:in `invoke_with_call_chain'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:571:in `invoke_with_call_chain'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:564:in `invoke'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:2019:in `invoke_task'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:1997:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:1997:in `each'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:1997:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:2036:in `standard_exception_handling'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:1991:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:1970:in `run'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:2036:in `standard_exception_handling'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:1967:in `run'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/bin/rake:31
/usr/bin/rake:19:in `load'
/usr/bin/rake:19
1
person has this problem
I have this problem, too!
Tell me when someone solves it.
The more people who report this problem, the more it gets noticed.
The more people who report this problem, the more it gets noticed.
The company has acknowledged this problem.
Create a customer community for your own organization
Plans starting at $19/month
-
Inappropriate?Thanks for letting us know. I'll investigate.
-
Inappropriate?I looked into this a bit more. The initializers are a bit odd. The gem load paths are set up after the process has yielded to the initializer block but before the environment file is loaded. By the time the environment specific file is loaded, all the gems have loaded and the paths have been initialized.
So all I can suggest is config.gem ... if RAILS_ENV=='production'.
Also, if enabled=false and developer=false in newrelic.yml then loading the gem is mostly a no-op anyway. I wouldn't be concerned about loading it in development. It will have zero runtime overhead if those settings are false.
The company says
this solves the problem
-
Inappropriate?thanks for your prompt reply!
so, just to clarifiy, this is a rails problem and RPM cant do anything? -
Inappropriate?That's tough to say. The problem is either that you're not supposed to load gems in the environment.rb (it's kind of implied by the sequence in the initializer) or a gem/plugin should not rely on the auto-loader--or both.
I can get this to work if I add the line:
require 'new_relic/agent.rb'
to config.rb in the start_agent method, line 190.
But this is the type of change that requires a lot of testing and validation in all the different modes and platforms so I can't just turn that out in a day or two.
If you try that I'd be interested in knowing if it works for you.
Loading Profile...



EMPLOYEE