[Ruby] Railsのエラー管理ツールのHoptoadを使ってみた
Railsのエラー管理がラクに出来るらしいので試しに設定してみました.
この手のツールは見てて楽しいので. 苦になりやすいエラー対応も気分良く出来そう.
導入方法やハマったこと等をまとめてみました.
アカウント登録
試してみるだけなので迷わずタダで使えるプランで!と見てみると
「Try Hoptoad FREE for 30 days」(お試し30日無料!)
なんて出てて無料プランが無いのか?と勘違いしました.
よーーく見ると下の方に
「Egg Plan for Free」(エッグプランは無料ですよ)
と小さく目立たずに書いてある。
あとは適当に入力項目を埋めていって「Create Account」
プロジェクト登録とRailsの設定
ログインしてプロジェクトを追加すると、Railsへのセットアップ方法がかかれています.
1. Remove your existing Exception Notifier from your ApplicationController(ExceptionNotifiableを使ってる場合は消してね):
class ApplicationController < ActionController::Base <del>include ExceptionNotifiable</del>
2. Add the hoptoad_notifier gem to config/environment.rb(config/environment.rb に gem hoptoad_notifierを追加):
config.gem 'hoptoad_notifier
3. Install the gem(rakeコマンドでインストール):
rake gems:install
4. Unpack the gem(gemをアンパック、vendor/plugins以下に配置されるだけなのでやらなくてもOK):
rake gems:unpack GEM=hoptoad_notifier
5. Configure the notifier(設定ファイルの生成):
script/generate hoptoad --api-key apikey123apikey123apikey123apikey123
6. Look for the exception to appear in your errors list(例外はHoptoadのエラーリストを見えると表示されるよー).
準備がこれで完了しました. あとは実際に通知をさせればHoptoadにエラーリストが表示されます.
エラーが見れるかテスト
プロジェクトルートで以下のコマンドを実行
rake hoptoad:test
$ rake hoptoad:test (in /Users/satoruk/Developments/foo) ** [Hoptoad] Notifier 2.3.0 ready to catch errors Configuration: http_open_timeout: 2 proxy_host: nil notifier_url: "http://hoptoadapp.com" port: 80 proxy_user: nil http_read_timeout: 5 api_key: "apikey123apikey123apikey123apikey123" notifier_version: "2.3.0" ignore: ["ActiveRecord::RecordNotFound", "ActionController::Rou development_environments: [] params_filters: ["password", "password_confirmation"] proxy_pass: nil ignore_by_filters: [] secure: false framework: "Rails: 2.3.8" project_root: "/Users/satoruk/Developments/foo" backtrace_filters: [#<Proc:0x00000001017033c8@/opt/local/lib/ruby/gems/1.8 proxy_port: nil ignore_user_agent: [] protocol: "http" host: "hoptoadapp.com" development_lookup: true notifier_name: "Hoptoad Notifier" environment_name: "development" Setting up the Controller. Processing request. Raising 'HoptoadTestingException' to simulate application failure. Sending request to http://hoptoadapp.com/notifier_api/v2/notices/: XMLのコードがずらりと ** [Hoptoad] Success: Net::HTTPOK ** [Hoptoad] Environment Info: [Ruby: 1.8.7] [Rails: 2.3.8] [Env: development] ** [Hoptoad] Response from Hoptoad: <?xml version="1.0" encoding="UTF-8"?> <notice> <error-id type="integer">1986027</error-id> <url>http://bar.hoptoadapp.com/errors/0000000/notices/00000000</url> <id type="integer">000000</id> </notice> Rendered layouts/_head (2.6ms) Rendered layouts/_groval_header (1.5ms) Rendered layouts/_copyright (0.8ms) Rendered layouts/_footer (7.6ms)
っでHoptoad上で見てみるとエラーがでてますと.
各エラーはUnresolvedとResolvedのステータスが変えられるのでエラーを調べ終わったらResolvedにしてく感じです.
ハマったところ
このまえのエントリーのエラー処理でrescue_action_in_publicを上書きしてたので、Hoptoadが動きませんでした. コードを読むとHoptoadはrescue_action_in_publicを利用しているので、以下のような回避策が必要です.
def rescue_action_in_public(exception) #:doc: unless hoptoad_ignore_user_agent? HoptoadNotifier.notify_or_ignore(exception, hoptoad_request_data) end # : # : # : end
Hoptoadがまともに動いてなかったとき、「rake hoptoad:test」の結果に以下のような内容があります.
Raising 'HoptoadTestingException' to simulate application failure.