【问题标题】:airbrake config for heroku+railsheroku+rails 的 airbrake 配置
【发布时间】:2016-05-12 14:15:00
【问题描述】:

我正在尝试配置 airbrake,但无法弄清楚。我想要实现的不是仅从生产环境中获取来自developmenttest 环境的错误。

但是,通过以下设置,我收到了所有 3 种类型的错误消息,因为它们是在生产中发生的。所以生产错误会发送生产错误通知,但开发/测试错误也会发送生产错误通知。

如何正确配置?

# Configures the environment the application is running in. Helps the Airbrake
# dashboard to distinguish between exceptions occurring in different
# environments. By default, it's not set.
# NOTE: This option must be set in order to make the 'ignore_environments'
# option work.
# https://github.com/airbrake/airbrake-ruby#environment
c.environment = :production 

# Setting this option allows Airbrake to filter exceptions occurring in
# unwanted environments such as :test. By default, it is equal to an empty
# Array, which means Airbrake Ruby sends exceptions occurring in all
# environments.
# NOTE: This option *does not* work if you don't set the 'environment' option.
# https://github.com/airbrake/airbrake-ruby#ignore_environments
c.ignore_environments = %w(test, development)

【问题讨论】:

    标签: ruby-on-rails heroku airbrake


    【解决方案1】:

    您可以像这样配置忽略的环境:

    c.ignore_environments = %w(test, development)
    # Which is equivalent to:
    c.ignore_environments = ['test,', 'development']
    

    配置这个选项的正确方法是这样的:

    c.ignore_environments = %w(test development)
    # Which is equivalent to:
    c.ignore_environments = ['test', 'development']
    

    如果您对数组使用 Ruby 的 %w 语法,则不想使用逗号。

    另一个潜在问题是您指定:

    c.environment = :production 
    

    在这里使用字符串(而不是符号)或Rails.env 会更加健壮。

    c.environment = Rails.env
    

    【讨论】:

    • kyrylo,哈哈哈。我甚至把它放在irb 只是为了确保它正确地发回数组。不知怎的,我错过了它:)。 c.environment = :production 来自官方文档。我对Rails.env 感到困惑。文档说By default, it's not set,但默认值是Rails.env,这对我来说似乎是矛盾的。
    • 默认情况下,airbrake-ruby 作为库不设置它。但是 airbrake gem 有一个 Rails 初始化程序,它知道 Rails 应用程序很可能会使用Rails.env,因此它可以方便地为您配置它。至于文档,他们也使用符号ignore_environments,所以这种行为在那里是一致的。快乐的空气制动!
    猜你喜欢
    • 2016-06-20
    • 2017-02-16
    • 2013-02-13
    • 2015-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多