heroku+rails 的 airbrake 配置

airbrake config for heroku+rails

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

不过,通过以下设置,我收到了生产中出现的所有 3 种类型的错误消息。因此,生产错误会发送生产错误通知,但 development/test 错误也会发送生产错误通知。

如何正确配置它?

# 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)

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

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