airbrake 3.0.9 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/CHANGELOG +162 -0
  2. data/Gemfile +1 -0
  3. data/INSTALL +0 -5
  4. data/README.md +60 -35
  5. data/README_FOR_HEROKU_ADDON.md +30 -29
  6. data/Rakefile +47 -15
  7. data/SUPPORTED_RAILS_VERSIONS +11 -0
  8. data/TESTING.md +6 -4
  9. data/airbrake.gemspec +5 -4
  10. data/features/metal.feature +2 -7
  11. data/features/rack.feature +1 -5
  12. data/features/rails.feature +9 -41
  13. data/features/rails_with_js_notifier.feature +20 -1
  14. data/features/rake.feature +2 -2
  15. data/features/sinatra.feature +1 -5
  16. data/features/step_definitions/rack_steps.rb +3 -0
  17. data/features/step_definitions/rails_application_steps.rb +39 -15
  18. data/features/support/airbrake_shim.rb.template +4 -8
  19. data/features/support/rails.rb +20 -3
  20. data/features/user_informer.feature +3 -3
  21. data/generators/airbrake/airbrake_generator.rb +6 -2
  22. data/generators/airbrake/templates/airbrake_tasks.rake +1 -1
  23. data/lib/airbrake.rb +2 -3
  24. data/lib/airbrake/capistrano.rb +3 -2
  25. data/lib/airbrake/configuration.rb +26 -8
  26. data/lib/airbrake/notice.rb +2 -2
  27. data/lib/airbrake/rack.rb +4 -1
  28. data/lib/airbrake/rails.rb +4 -5
  29. data/lib/airbrake/rails/controller_methods.rb +19 -13
  30. data/lib/airbrake/rails/javascript_notifier.rb +1 -1
  31. data/lib/airbrake/rails/middleware/exceptions_catcher.rb +27 -0
  32. data/lib/airbrake/rails3_tasks.rb +4 -1
  33. data/lib/airbrake/railtie.rb +19 -4
  34. data/lib/airbrake/rake_handler.rb +1 -1
  35. data/lib/airbrake/sender.rb +2 -7
  36. data/lib/airbrake/shared_tasks.rb +9 -3
  37. data/lib/airbrake/user_informer.rb +1 -1
  38. data/lib/airbrake/version.rb +1 -1
  39. data/lib/airbrake_tasks.rb +11 -8
  40. data/lib/rails/generators/airbrake/airbrake_generator.rb +6 -2
  41. data/script/integration_test.rb +1 -1
  42. data/test/airbrake_tasks_test.rb +2 -2
  43. data/test/backtrace_test.rb +0 -1
  44. data/test/configuration_test.rb +2 -2
  45. data/test/helper.rb +0 -4
  46. data/test/notice_test.rb +3 -1
  47. data/test/notifier_test.rb +1 -1
  48. data/test/sender_test.rb +18 -18
  49. metadata +151 -233
  50. data/.gitignore +0 -18
  51. data/.yardopts +0 -3
  52. data/features/step_definitions/airbrake_shim.rb.template +0 -15
@@ -1,15 +1,11 @@
1
1
  require 'sham_rack'
2
2
 
3
- ShamRack.at("airbrake.io") do |env|
4
- xml = env['rack.input'].read
5
- puts "Recieved the following exception:\n#{xml}"
3
+ ShamRack.at("api.airbrake.io") do |env|
6
4
  response = <<-end_xml
7
- <?xml version="1.0" encoding="UTF-8"?>
8
5
  <notice>
9
- <error-id type="integer">3799307</error-id>
10
- <url>http://sample.airbrake.io/errors/3799307/notices/643732254</url>
11
- <id type="integer">643732254</id>
6
+ <id>b6817316-9c45-ed26-45eb-780dbb86aadb</id>
7
+ <url>http://airbrake.io/locate/b6817316-9c45-ed26-45eb-780dbb86aadb</url>
12
8
  </notice>
13
9
  end_xml
14
- ["200 OK", { "Content-type" => "text/xml" }, response]
10
+ ["200 OK", { "Content-type" => "text/xml" }, [response]]
15
11
  end
@@ -21,7 +21,9 @@ module RailsHelpers
21
21
 
22
22
  def rails_version
23
23
  @rails_version ||= begin
24
- if bundler_manages_gems?
24
+ if ENV["RAILS_VERSION"]
25
+ ENV["RAILS_VERSION"]
26
+ elsif bundler_manages_gems?
25
27
  rails_version = open(gemfile_path).read.match(/gem.*rails["'].*["'](.+)["']/)[1]
26
28
  else
27
29
  environment_file = File.join(rails_root, 'config', 'environment.rb')
@@ -50,6 +52,10 @@ module RailsHelpers
50
52
  rails3? || rails_version =~ /^2\./
51
53
  end
52
54
 
55
+ def version_string
56
+ ENV['RAILS_VERSION'] || `tail -n 1 SUPPORTED_RAILS_VERSIONS` # use latest version if ENV["RAILS_VERSION"] is undefined
57
+ end
58
+
53
59
  def environment_path
54
60
  File.join(rails_root, 'config', 'environment.rb')
55
61
  end
@@ -110,7 +116,8 @@ module RailsHelpers
110
116
  def perform_request(uri, environment = 'production')
111
117
  if rails3?
112
118
  request_script = <<-SCRIPT
113
- require 'config/environment'
119
+ require File.expand_path('../config/environment', __FILE__)
120
+
114
121
 
115
122
  env = Rack::MockRequest.env_for(#{uri.inspect})
116
123
  response = RailsRoot::Application.call(env).last
@@ -126,7 +133,7 @@ module RailsHelpers
126
133
  @terminal.run("ruby -rthread ./script/rails runner -e #{environment} request.rb")
127
134
  elsif rails_uses_rack?
128
135
  request_script = <<-SCRIPT
129
- require 'config/environment'
136
+ require File.expand_path('../config/environment', __FILE__)
130
137
 
131
138
  env = Rack::MockRequest.env_for(#{uri.inspect})
132
139
  app = Rack::Lint.new(ActionController::Dispatcher.new)
@@ -176,6 +183,16 @@ module RailsHelpers
176
183
  @terminal.run("ruby -rthread ./script/runner -e #{environment} request.rb")
177
184
  end
178
185
  end
186
+
187
+ def monkeypatch_old_version
188
+ monkeypatchin= <<-MONKEYPATCHIN
189
+
190
+ MissingSourceFile::REGEXPS << [/^cannot load such file -- (.+)$/i, 1]
191
+
192
+ MONKEYPATCHIN
193
+
194
+ File.open(File.join(rails_root,"config","initializers", 'monkeypatchin.rb'), 'w') { |file| file.write(monkeypatchin) }
195
+ end
179
196
  end
180
197
 
181
198
  World(RailsHelpers)
@@ -18,7 +18,7 @@ Feature: Inform the user of the airbrake notice that was just created
18
18
  """
19
19
  And I route "/test/index" to "test#index"
20
20
  And I perform a request to "http://example.com:123/test/index?param=value"
21
- Then I should see "Airbrake Error 3799307"
21
+ Then I should see "Airbrake Error b6817316-9c45-ed26-45eb-780dbb86aadb"
22
22
 
23
23
  Scenario: Rescue an exception in a controller with a custom error string
24
24
  When I generate a new Rails application
@@ -39,7 +39,7 @@ Feature: Inform the user of the airbrake notice that was just created
39
39
  """
40
40
  And I route "/test/index" to "test#index"
41
41
  And I perform a request to "http://example.com:123/test/index?param=value"
42
- Then I should see "Error #3799307"
42
+ Then I should see "Error #b6817316-9c45-ed26-45eb-780dbb86aadb"
43
43
 
44
44
  Scenario: Don't inform them user
45
45
  When I generate a new Rails application
@@ -60,4 +60,4 @@ Feature: Inform the user of the airbrake notice that was just created
60
60
  """
61
61
  And I route "/test/index" to "test#index"
62
62
  And I perform a request to "http://example.com:123/test/index?param=value"
63
- Then I should not see "Airbrake Error 3799307"
63
+ Then I should not see "Airbrake Error b6817316-9c45-ed26-45eb-780dbb86aadb"
@@ -60,9 +60,13 @@ class AirbrakeGenerator < Rails::Generator::Base
60
60
  end
61
61
  end
62
62
 
63
+ def heroku_var(var,app_name = nil)
64
+ app = app_name ? "--app #{app_name}" : ''
65
+ `heroku config #{app} | grep -E "#{var.upcase}" | awk '{ print $3; }'`.strip
66
+ end
67
+
63
68
  def heroku_api_key
64
- app = options[:app] ? " --app #{options[:app]}" : ''
65
- `heroku console#{app} 'puts ENV[%{HOPTOAD_API_KEY}]'`.split("\n").first
69
+ heroku_var("(hoptoad|airbrake)_api_key",options[:app]).split.find {|x| x unless x.blank?}
66
70
  end
67
71
 
68
72
  def heroku?
@@ -3,7 +3,7 @@
3
3
  # https://thoughtbot.lighthouseapp.com/projects/14221/tickets/629
4
4
  unless ARGV.any? {|a| a =~ /^gems/}
5
5
 
6
- Dir[File.join(RAILS_ROOT, 'vendor', 'gems', 'airbrake-*')].each do |vendored_notifier|
6
+ Dir[File.join(Rails.root, 'vendor', 'gems', 'airbrake-*')].each do |vendored_notifier|
7
7
  $: << File.join(vendored_notifier, 'lib')
8
8
  end
9
9
 
@@ -18,7 +18,6 @@ require 'airbrake/user_informer'
18
18
 
19
19
  require 'airbrake/railtie' if defined?(Rails::Railtie)
20
20
 
21
- # Gem for applications to automatically post errors to the Airbrake of their choice.
22
21
  module Airbrake
23
22
  API_VERSION = "2.2"
24
23
  LOG_PREFIX = "** [Airbrake] "
@@ -55,8 +54,8 @@ module Airbrake
55
54
  # Returns the Ruby version, Rails version, and current Rails environment
56
55
  def environment_info
57
56
  info = "[Ruby: #{RUBY_VERSION}]"
58
- info << " [#{configuration.framework}]"
59
- info << " [Env: #{configuration.environment_name}]"
57
+ info << " [#{configuration.framework}]" if configuration.framework
58
+ info << " [Env: #{configuration.environment_name}]" if configuration.environment_name
60
59
  end
61
60
 
62
61
  # Writes out the given message to the #logger
@@ -14,11 +14,12 @@ module Airbrake
14
14
  - Run remotely so we use remote API keys, environment, etc.
15
15
  DESC
16
16
  task :deploy, :except => { :no_release => true } do
17
- rails_env = fetch(:airbrake_env, fetch(:rails_env, "production"))
17
+ rails_env = fetch(:rails_env, "production")
18
+ airbrake_env = fetch(:airbrake_env, fetch(:rails_env, "production"))
18
19
  local_user = ENV['USER'] || ENV['USERNAME']
19
20
  executable = RUBY_PLATFORM.downcase.include?('mswin') ? fetch(:rake, 'rake.bat') : fetch(:rake, 'rake')
20
21
  directory = configuration.current_release
21
- notify_command = "cd #{directory}; #{executable} RAILS_ENV=#{rails_env} airbrake:deploy TO=#{rails_env} REVISION=#{current_revision} REPO=#{repository} USER=#{local_user}"
22
+ notify_command = "cd #{directory}; #{executable} RAILS_ENV=#{rails_env} airbrake:deploy TO=#{airbrake_env} REVISION=#{current_revision} REPO=#{repository} USER=#{local_user}"
22
23
  notify_command << " DRY_RUN=true" if dry_run
23
24
  notify_command << " API_KEY=#{ENV['API_KEY']}" if ENV['API_KEY']
24
25
  logger.info "Notifying Airbrake of Deploy (#{notify_command})"
@@ -2,7 +2,7 @@ module Airbrake
2
2
  # Used to set up and modify settings for the notifier.
3
3
  class Configuration
4
4
 
5
- OPTIONS = [:api_key, :backtrace_filters, :development_environments,
5
+ OPTIONS = [:api_key, :js_api_key, :backtrace_filters, :development_environments,
6
6
  :development_lookup, :environment_name, :host,
7
7
  :http_open_timeout, :http_read_timeout, :ignore, :ignore_by_filters,
8
8
  :ignore_user_agent, :notifier_name, :notifier_url, :notifier_version,
@@ -12,6 +12,12 @@ module Airbrake
12
12
 
13
13
  # The API key for your project, found on the project edit form.
14
14
  attr_accessor :api_key
15
+
16
+ # If you're using the Javascript notifier and would want to separate
17
+ # Javascript notifications into another Airbrake project, specify
18
+ # its APi key here.
19
+ # Defaults to #api_key (of the base project)
20
+ attr_writer :js_api_key
15
21
 
16
22
  # The host to connect to (defaults to airbrake.io).
17
23
  attr_accessor :host
@@ -69,7 +75,7 @@ module Airbrake
69
75
  # The name of the environment the application is running in
70
76
  attr_accessor :environment_name
71
77
 
72
- # The path to the project in which the error occurred, such as the RAILS_ROOT
78
+ # The path to the project in which the error occurred, such as the Rails.root
73
79
  attr_accessor :project_root
74
80
 
75
81
  # The name of the notifier library being used to send notifications (such as "Airbrake Notifier")
@@ -120,7 +126,8 @@ module Airbrake
120
126
  'ActionController::InvalidAuthenticityToken',
121
127
  'CGI::Session::CookieStore::TamperedWithCookie',
122
128
  'ActionController::UnknownAction',
123
- 'AbstractController::ActionNotFound']
129
+ 'AbstractController::ActionNotFound',
130
+ 'Mongoid::Errors::DocumentNotFound']
124
131
 
125
132
  alias_method :secure?, :secure
126
133
  alias_method :use_system_ssl_cert_chain?, :use_system_ssl_cert_chain
@@ -128,7 +135,7 @@ module Airbrake
128
135
  def initialize
129
136
  @secure = false
130
137
  @use_system_ssl_cert_chain= false
131
- @host = 'airbrake.io'
138
+ @host = 'api.airbrake.io'
132
139
  @http_open_timeout = 2
133
140
  @http_read_timeout = 5
134
141
  @params_filters = DEFAULT_PARAMS_FILTERS.dup
@@ -140,7 +147,7 @@ module Airbrake
140
147
  @development_lookup = true
141
148
  @notifier_name = 'Airbrake Notifier'
142
149
  @notifier_version = VERSION
143
- @notifier_url = 'http://airbrake.io'
150
+ @notifier_url = 'https://github.com/airbrake/airbrake'
144
151
  @framework = 'Standalone'
145
152
  @user_information = 'Airbrake Error {{error_id}}'
146
153
  @rescue_rake_exceptions = nil
@@ -152,7 +159,7 @@ module Airbrake
152
159
  #
153
160
  # @example
154
161
  # config.filter_bracktrace do |line|
155
- # line.gsub(/^#{Rails.root}/, "[RAILS_ROOT]")
162
+ # line.gsub(/^#{Rails.root}/, "[Rails.root]")
156
163
  # end
157
164
  #
158
165
  # @param [Proc] block The new backtrace filter.
@@ -199,7 +206,8 @@ module Airbrake
199
206
  # Returns a hash of all configurable options
200
207
  def to_hash
201
208
  OPTIONS.inject({}) do |hash, option|
202
- hash.merge(option.to_sym => send(option))
209
+ hash[option.to_sym] = self.send(option)
210
+ hash
203
211
  end
204
212
  end
205
213
 
@@ -220,6 +228,9 @@ module Airbrake
220
228
  @port || default_port
221
229
  end
222
230
 
231
+ # Determines whether protocol should be "http" or "https".
232
+ # @return [String] Returns +"http"+ if you've set secure to +false+ in
233
+ # configuration, and +"https"+ otherwise.
223
234
  def protocol
224
235
  if secure?
225
236
  'https'
@@ -228,6 +239,10 @@ module Airbrake
228
239
  end
229
240
  end
230
241
 
242
+ def js_api_key
243
+ @js_api_key || self.api_key
244
+ end
245
+
231
246
  def js_notifier=(*args)
232
247
  warn '[AIRBRAKE] config.js_notifier has been deprecated and has no effect. You should use <%= airbrake_javascript_notifier %> directly at the top of your layouts. Be sure to place it before all other javascript.'
233
248
  end
@@ -236,7 +251,7 @@ module Airbrake
236
251
  warn 'config.environment_filters has been deprecated and has no effect.'
237
252
  []
238
253
  end
239
-
254
+
240
255
  def ca_bundle_path
241
256
  if use_system_ssl_cert_chain? && File.exist?(OpenSSL::X509::DEFAULT_CERT_FILE)
242
257
  OpenSSL::X509::DEFAULT_CERT_FILE
@@ -250,6 +265,9 @@ module Airbrake
250
265
  end
251
266
 
252
267
  private
268
+ # Determines what port should we use for sending notices.
269
+ # @return [Fixnum] Returns 443 if you've set secure to true in your
270
+ # configuration, and 80 otherwise.
253
271
  def default_port
254
272
  if secure?
255
273
  443
@@ -45,7 +45,7 @@ module Airbrake
45
45
  # A hash of session data from the request
46
46
  attr_reader :session_data
47
47
 
48
- # The path to the project that caused the error (usually RAILS_ROOT)
48
+ # The path to the project that caused the error (usually Rails.root)
49
49
  attr_reader :project_root
50
50
 
51
51
  # The URL at which the error occurred (if any)
@@ -284,7 +284,7 @@ module Airbrake
284
284
 
285
285
  def filter_key?(key)
286
286
  params_filters.any? do |filter|
287
- key.to_s.include?(filter.to_s)
287
+ key.to_s.eql?(filter.to_s)
288
288
  end
289
289
  end
290
290
 
@@ -12,14 +12,17 @@ module Airbrake
12
12
  # end
13
13
  #
14
14
  # app = Rack::Builder.app do
15
- # use Airbrake::Rack
16
15
  # run lambda { |env| raise "Rack down" }
17
16
  # end
18
17
  #
18
+ # use Airbrake::Rack
19
+ # run app
20
+ #
19
21
  # Use a standard Airbrake.configure call to configure your api key.
20
22
  class Rack
21
23
  def initialize(app)
22
24
  @app = app
25
+ Airbrake.configuration.logger ||= Logger.new STDOUT
23
26
  end
24
27
 
25
28
  def call(env)
@@ -28,14 +28,13 @@ module Airbrake
28
28
  end
29
29
 
30
30
  Airbrake.configure(true) do |config|
31
- config.logger = rails_logger
32
- config.environment_name = RAILS_ENV if defined?(RAILS_ENV)
33
- config.project_root = RAILS_ROOT if defined?(RAILS_ROOT)
34
- config.framework = "Rails: #{::Rails::VERSION::STRING}" if defined?(::Rails::VERSION)
31
+ config.logger = rails_logger
32
+ config.environment_name = defined?(::Rails.env) && ::Rails.env || defined?(RAILS_ENV) && RAILS_ENV
33
+ config.project_root = defined?(::Rails.root) && ::Rails.root || defined?(RAILS_ROOT) && RAILS_ROOT
34
+ config.framework = defined?(::Rails.version) && "Rails: #{::Rails.version}" || defined?(::Rails::VERSION::STRING) && "Rails: #{::Rails::VERSION::STRING}"
35
35
  end
36
36
  end
37
37
  end
38
38
  end
39
39
 
40
40
  Airbrake::Rails.initialize
41
-
@@ -1,6 +1,16 @@
1
1
  module Airbrake
2
2
  module Rails
3
3
  module ControllerMethods
4
+
5
+ def airbrake_request_data
6
+ { :parameters => airbrake_filter_if_filtering(params.to_hash),
7
+ :session_data => airbrake_filter_if_filtering(airbrake_session_data),
8
+ :controller => params[:controller],
9
+ :action => params[:action],
10
+ :url => airbrake_request_url,
11
+ :cgi_data => airbrake_filter_if_filtering(request.env) }
12
+ end
13
+
4
14
  private
5
15
 
6
16
  # This method should be used for sending manual notifications while you are still
@@ -13,9 +23,9 @@ module Airbrake
13
23
 
14
24
  def airbrake_local_request?
15
25
  if defined?(::Rails.application.config)
16
- ::Rails.application.config.consider_all_requests_local || request.local?
26
+ ::Rails.application.config.consider_all_requests_local || (request.local? && (!request.env["HTTP_X_FORWARDED_FOR"]))
17
27
  else
18
- consider_all_requests_local || local_request?
28
+ consider_all_requests_local || (local_request? && (!request.env["HTTP_X_FORWARDED_FOR"]))
19
29
  end
20
30
  end
21
31
 
@@ -25,23 +35,19 @@ module Airbrake
25
35
  Airbrake.configuration.ignore_user_agent.flatten.any? { |ua| ua === user_agent }
26
36
  end
27
37
 
28
- def airbrake_request_data
29
- { :parameters => airbrake_filter_if_filtering(params.to_hash),
30
- :session_data => airbrake_filter_if_filtering(airbrake_session_data),
31
- :controller => params[:controller],
32
- :action => params[:action],
33
- :url => airbrake_request_url,
34
- :cgi_data => airbrake_filter_if_filtering(request.env) }
35
- end
36
38
 
37
39
  def airbrake_filter_if_filtering(hash)
38
40
  return hash if ! hash.is_a?(Hash)
39
41
 
40
- if respond_to?(:filter_parameters)
41
- filter_parameters(hash) rescue hash
42
+
43
+ if respond_to?(:filter_parameters) # Rails 2
44
+ filter_parameters(hash)
45
+ elsif defined?(ActionDispatch::Http::ParameterFilter) # Rails 3
46
+ ActionDispatch::Http::ParameterFilter.new(::Rails.application.config.filter_parameters).filter(hash)
42
47
  else
43
48
  hash
44
- end
49
+ end rescue hash
50
+
45
51
  end
46
52
 
47
53
  def airbrake_session_data
@@ -21,7 +21,7 @@ module Airbrake
21
21
  :use_full_path => false,
22
22
  :locals => {
23
23
  :host => host,
24
- :api_key => Airbrake.configuration.api_key,
24
+ :api_key => Airbrake.configuration.js_api_key,
25
25
  :environment => Airbrake.configuration.environment_name,
26
26
  :action_name => action_name,
27
27
  :controller_name => controller_name,
@@ -0,0 +1,27 @@
1
+ module Airbrake
2
+ module Rails
3
+ module Middleware
4
+ module ExceptionsCatcher
5
+ def self.included(base)
6
+ base.send(:alias_method_chain,:render_exception,:airbrake)
7
+ end
8
+
9
+ def skip_user_agent?(env)
10
+ user_agent = env["HTTP_USER_AGENT"]
11
+ ::Airbrake.configuration.ignore_user_agent.flatten.any? { |ua| ua === user_agent }
12
+ rescue
13
+ false
14
+ end
15
+
16
+ def render_exception_with_airbrake(env,exception)
17
+ controller = env['action_controller.instance']
18
+ env['airbrake.error_id'] = Airbrake.notify_or_ignore(exception, controller.airbrake_request_data) unless skip_user_agent?(env)
19
+ if defined?(controller.rescue_action_in_public_without_airbrake)
20
+ controller.rescue_action_in_public_without_airbrake(exception)
21
+ end
22
+ render_exception_without_airbrake(env,exception)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -4,7 +4,10 @@ require File.join(File.dirname(__FILE__), 'shared_tasks')
4
4
  namespace :airbrake do
5
5
  desc "Verify your gem installation by sending a test exception to the airbrake service"
6
6
  task :test => [:environment] do
7
- Rails.logger = Logger.new(STDOUT)
7
+ Rails.logger = defined?(ActiveSupport::TaggedLogging) ?
8
+ ActiveSupport::TaggedLogging.new(Logger.new(STDOUT)) :
9
+ Logger.new(STDOUT)
10
+
8
11
  Rails.logger.level = Logger::DEBUG
9
12
  Airbrake.configure(true) do |config|
10
13
  config.logger = Rails.logger
@@ -9,8 +9,8 @@ module Airbrake
9
9
  end
10
10
 
11
11
  initializer "airbrake.use_rack_middleware" do |app|
12
- app.config.middleware.use "Airbrake::Rack"
13
12
  app.config.middleware.insert 0, "Airbrake::UserInformer"
13
+ app.config.middleware.insert_after "Airbrake::UserInformer","Airbrake::Rack"
14
14
  end
15
15
 
16
16
  config.after_initialize do
@@ -21,12 +21,27 @@ module Airbrake
21
21
  config.framework = "Rails: #{::Rails::VERSION::STRING}"
22
22
  end
23
23
 
24
- if defined?(::ActionController::Base)
24
+ ActiveSupport.on_load(:action_controller) do
25
+ # Lazily load action_controller methods
26
+ #
25
27
  require 'airbrake/rails/javascript_notifier'
26
28
  require 'airbrake/rails/controller_methods'
27
29
 
28
- ::ActionController::Base.send(:include, Airbrake::Rails::ControllerMethods)
29
- ::ActionController::Base.send(:include, Airbrake::Rails::JavascriptNotifier)
30
+ include Airbrake::Rails::JavascriptNotifier
31
+ include Airbrake::Rails::ControllerMethods
32
+ end
33
+
34
+ if defined?(::ActionDispatch::DebugExceptions)
35
+ # We should catch the exceptions in ActionDispatch::DebugExceptions in Rails 3.2.x.
36
+ #
37
+ require 'airbrake/rails/middleware/exceptions_catcher'
38
+ ::ActionDispatch::DebugExceptions.send(:include,Airbrake::Rails::Middleware::ExceptionsCatcher)
39
+ elsif defined?(::ActionDispatch::ShowExceptions)
40
+ # ActionDispatch::DebugExceptions is not defined in Rails 3.0.x and 3.1.x so
41
+ # catch the exceptions in ShowExceptions.
42
+ #
43
+ require 'airbrake/rails/middleware/exceptions_catcher'
44
+ ::ActionDispatch::ShowExceptions.send(:include,Airbrake::Rails::Middleware::ExceptionsCatcher)
30
45
  end
31
46
  end
32
47
  end