Class: Bulletproof::Middleware
- Inherits:
-
Object
- Object
- Bulletproof::Middleware
- Defined in:
- lib/bulletproof/middleware.rb
Overview
Rack ミドルウェア。リクエストごとに AR ロード件数・GC 負荷を計測し、 閾値を超えた場合は設定済みの通知先へ RuntimeWarning を送る。
通知先:
rails_logger: true → Rails.logger.warn に出力
console: true → HTML に console.warn を注入(開発者ツール Console タブ)
alert: true → HTML にオーバーレイパネルを注入(画面上で確認)
log_file: "path" → ファイルに追記
notifier: callable → Slack 等カスタム通知先
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, config = Bulletproof.config) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app, config = Bulletproof.config) ⇒ Middleware
Returns a new instance of Middleware.
17 18 19 20 21 |
# File 'lib/bulletproof/middleware.rb', line 17 def initialize(app, config = Bulletproof.config) @app = app @config = config @monitor = Runtime::RequestMonitor.new(config) end |
Instance Method Details
#call(env) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/bulletproof/middleware.rb', line 23 def call(env) response, warnings = @monitor.monitor { @app.call(env) } return response if warnings.empty? notify_logger(warnings) notify_log_file(warnings) notify_custom(warnings) inject_html(response, warnings) end |