1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Airbrakeで特定の条件の時に通知を行わないようにする

Posted at

Airbrake.add_filterというAPIでAirbrake.notifyをフックし、Airbrake::Notice#ignore!を実行することで通知を無効にすることができる。

例えば、Railsなどでボットからのリクエストは通知から除外したいとき

/config/initializers/airbrake.rbなど
crawler_uas = %w(
  Baiduspider
  Bingbot
  Googlebot
  Yahoo!\ Slurp
)

Airbrake.add_filter do |notice|
  if crawler_uas.any? { |crawler| notice[:context][:userAgent] =~ /#{crawler}/i }
    notice.ignore!
  end
end

Rackの場合はnotice[:environment]からリファラやHTTPヘッダの情報もとれるので、より複雑な条件を書くことも可能です。

参考) https://github.com/airbrake/airbrake-ruby#airbrakeadd_filter

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?