【问题标题】:newrelic_rpm: undefined method `before_save' for #<Class:0x00000004a28b28>newrelic_rpm:#<Class:0x00000004a28b28> 的未定义方法“before_save”
【发布时间】:2013-05-15 16:11:05
【问题描述】:

自从我在 Heroku 应用上将 newrelic_rpm gem 从 3.5.8.72 更新到 3.6.1.88 后,我注意到 newrelic 正在加载我的 rake 任务,给我带来了奇怪的错误:

rake aborted!
undefined method `before_save' for #<Class:0x00000003d2f908>
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/dynamic_matchers.rb:55:in `method_missing'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/session_store.rb:90:in `<class:Session>'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/session_store.rb:79:in `<class:SessionStore>'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/session_store.rb:53:in `<module:ActiveRecord>'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/session_store.rb:3:in `<top (required)>'
/app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/application/configuration.rb:138:in `session_store'
/app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/application.rb:273:in `block in default_middleware_stack'
/app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/application.rb:237:in `tap'
/app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/application.rb:237:in `default_middleware_stack'
/app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/engine.rb:469:in `app'
...

我知道问题肯定来自 newrelic_rpm,所以我想知道如何以某种方式在 rake 任务中禁用它。

我尝试使用https://newrelic.com/docs/ruby/forcing-the-ruby-agent-to-start 设置 ENV var,但它也会禁用 webapp 的 newrelic。有没有办法为我的所有 rake 任务设置 ENV var,但只能在 rake 上而不是在网络服务器中?

提前非常感谢!

【问题讨论】:

    标签: heroku rake newrelic


    【解决方案1】:

    最佳解决方案取决于您运行 rake 任务的方式。例如,如果您从 cronjob 运行它,那么您可以将 NEWRELIC_ENABLE=false 添加到您的 rake 任务的 cron 条目中。

    否则,如果您手动运行 rake 任务,则应将以下内容添加到 newrelic.yml 文件中。

    autostart.blacklisted_executables: rake

    这将阻止代理在可执行文件称为 rake 的任何情况下启动。请注意,如果您希望阻止 New Relic 在其中启动其他可执行文件,这也可以是逗号分隔的列表。

    【讨论】:

    • 非常感谢史蒂文。我正在使用 cronjobs,并且希望避免将 NEWRELIC_ENABLE=false 添加到每个条目中(将来可能会很棘手)。所以文件 newrelic.yml 的行是完美的!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-12
    • 1970-01-01
    • 1970-01-01
    • 2020-05-30
    • 1970-01-01
    • 2016-05-19
    相关资源
    最近更新 更多