airbrake 3.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/.yardopts +3 -0
- data/CHANGELOG +441 -0
- data/Gemfile +3 -0
- data/INSTALL +25 -0
- data/MIT-LICENSE +22 -0
- data/README.md +431 -0
- data/README_FOR_HEROKU_ADDON.md +93 -0
- data/Rakefile +188 -0
- data/SUPPORTED_RAILS_VERSIONS +14 -0
- data/TESTING.md +26 -0
- data/airbrake.gemspec +33 -0
- data/features/metal.feature +23 -0
- data/features/rack.feature +27 -0
- data/features/rails.feature +254 -0
- data/features/rails_with_js_notifier.feature +78 -0
- data/features/rake.feature +23 -0
- data/features/sinatra.feature +33 -0
- data/features/step_definitions/airbrake_shim.rb.template +15 -0
- data/features/step_definitions/file_steps.rb +10 -0
- data/features/step_definitions/metal_steps.rb +23 -0
- data/features/step_definitions/rack_steps.rb +20 -0
- data/features/step_definitions/rails_application_steps.rb +401 -0
- data/features/step_definitions/rake_steps.rb +17 -0
- data/features/support/airbrake_shim.rb.template +15 -0
- data/features/support/env.rb +18 -0
- data/features/support/matchers.rb +35 -0
- data/features/support/rails.rb +181 -0
- data/features/support/rake/Rakefile +57 -0
- data/features/support/terminal.rb +103 -0
- data/features/user_informer.feature +63 -0
- data/generators/airbrake/airbrake_generator.rb +90 -0
- data/generators/airbrake/lib/insert_commands.rb +34 -0
- data/generators/airbrake/lib/rake_commands.rb +24 -0
- data/generators/airbrake/templates/airbrake_tasks.rake +25 -0
- data/generators/airbrake/templates/capistrano_hook.rb +6 -0
- data/generators/airbrake/templates/initializer.rb +6 -0
- data/install.rb +1 -0
- data/lib/airbrake.rb +150 -0
- data/lib/airbrake/backtrace.rb +100 -0
- data/lib/airbrake/capistrano.rb +21 -0
- data/lib/airbrake/configuration.rb +247 -0
- data/lib/airbrake/notice.rb +348 -0
- data/lib/airbrake/rack.rb +42 -0
- data/lib/airbrake/rails.rb +41 -0
- data/lib/airbrake/rails/action_controller_catcher.rb +30 -0
- data/lib/airbrake/rails/controller_methods.rb +68 -0
- data/lib/airbrake/rails/error_lookup.rb +33 -0
- data/lib/airbrake/rails/javascript_notifier.rb +42 -0
- data/lib/airbrake/rails3_tasks.rb +82 -0
- data/lib/airbrake/railtie.rb +33 -0
- data/lib/airbrake/rake_handler.rb +65 -0
- data/lib/airbrake/sender.rb +83 -0
- data/lib/airbrake/shared_tasks.rb +30 -0
- data/lib/airbrake/tasks.rb +83 -0
- data/lib/airbrake/user_informer.rb +25 -0
- data/lib/airbrake/version.rb +3 -0
- data/lib/airbrake_tasks.rb +50 -0
- data/lib/rails/generators/airbrake/airbrake_generator.rb +96 -0
- data/lib/templates/javascript_notifier.erb +13 -0
- data/lib/templates/rescue.erb +91 -0
- data/rails/init.rb +1 -0
- data/script/integration_test.rb +38 -0
- data/test/airbrake_2_2.xsd +78 -0
- data/test/airbrake_tasks_test.rb +163 -0
- data/test/backtrace_test.rb +163 -0
- data/test/catcher_test.rb +333 -0
- data/test/configuration_test.rb +216 -0
- data/test/helper.rb +251 -0
- data/test/javascript_notifier_test.rb +52 -0
- data/test/logger_test.rb +85 -0
- data/test/notice_test.rb +459 -0
- data/test/notifier_test.rb +235 -0
- data/test/rack_test.rb +58 -0
- data/test/rails_initializer_test.rb +36 -0
- data/test/recursion_test.rb +10 -0
- data/test/sender_test.rb +193 -0
- data/test/user_informer_test.rb +29 -0
- metadata +365 -0
@@ -0,0 +1,42 @@
|
|
1
|
+
module Airbrake
|
2
|
+
# Middleware for Rack applications. Any errors raised by the upstream
|
3
|
+
# application will be delivered to Airbrake and re-raised.
|
4
|
+
#
|
5
|
+
# Synopsis:
|
6
|
+
#
|
7
|
+
# require 'rack'
|
8
|
+
# require 'airbrake'
|
9
|
+
#
|
10
|
+
# Airbrake.configure do |config|
|
11
|
+
# config.api_key = 'my_api_key'
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# app = Rack::Builder.app do
|
15
|
+
# use Airbrake::Rack
|
16
|
+
# run lambda { |env| raise "Rack down" }
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# Use a standard Airbrake.configure call to configure your api key.
|
20
|
+
class Rack
|
21
|
+
def initialize(app)
|
22
|
+
@app = app
|
23
|
+
end
|
24
|
+
|
25
|
+
def call(env)
|
26
|
+
begin
|
27
|
+
response = @app.call(env)
|
28
|
+
rescue Exception => raised
|
29
|
+
error_id = Airbrake.notify_or_ignore(raised, :rack_env => env)
|
30
|
+
env['airbrake.error_id'] = error_id
|
31
|
+
raise
|
32
|
+
end
|
33
|
+
|
34
|
+
if env['rack.exception']
|
35
|
+
error_id = Airbrake.notify_or_ignore(env['rack.exception'], :rack_env => env)
|
36
|
+
env['airbrake.error_id'] = error_id
|
37
|
+
end
|
38
|
+
|
39
|
+
response
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'airbrake'
|
2
|
+
require 'airbrake/rails/controller_methods'
|
3
|
+
require 'airbrake/rails/action_controller_catcher'
|
4
|
+
require 'airbrake/rails/error_lookup'
|
5
|
+
require 'airbrake/rails/javascript_notifier'
|
6
|
+
|
7
|
+
module Airbrake
|
8
|
+
module Rails
|
9
|
+
def self.initialize
|
10
|
+
if defined?(ActionController::Base)
|
11
|
+
ActionController::Base.send(:include, Airbrake::Rails::ActionControllerCatcher)
|
12
|
+
ActionController::Base.send(:include, Airbrake::Rails::ErrorLookup)
|
13
|
+
ActionController::Base.send(:include, Airbrake::Rails::ControllerMethods)
|
14
|
+
ActionController::Base.send(:include, Airbrake::Rails::JavascriptNotifier)
|
15
|
+
end
|
16
|
+
|
17
|
+
rails_logger = if defined?(::Rails.logger)
|
18
|
+
::Rails.logger
|
19
|
+
elsif defined?(RAILS_DEFAULT_LOGGER)
|
20
|
+
RAILS_DEFAULT_LOGGER
|
21
|
+
end
|
22
|
+
|
23
|
+
if defined?(::Rails.configuration) && ::Rails.configuration.respond_to?(:middleware)
|
24
|
+
::Rails.configuration.middleware.insert_after 'ActionController::Failsafe',
|
25
|
+
Airbrake::Rack
|
26
|
+
::Rails.configuration.middleware.insert_after 'Rack::Lock',
|
27
|
+
Airbrake::UserInformer
|
28
|
+
end
|
29
|
+
|
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)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
Airbrake::Rails.initialize
|
41
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Airbrake
|
2
|
+
module Rails
|
3
|
+
module ActionControllerCatcher
|
4
|
+
|
5
|
+
# Sets up an alias chain to catch exceptions when Rails does
|
6
|
+
def self.included(base) #:nodoc:
|
7
|
+
base.send(:alias_method, :rescue_action_in_public_without_airbrake, :rescue_action_in_public)
|
8
|
+
base.send(:alias_method, :rescue_action_in_public, :rescue_action_in_public_with_airbrake)
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
# Overrides the rescue_action method in ActionController::Base, but does not inhibit
|
14
|
+
# any custom processing that is defined with Rails 2's exception helpers.
|
15
|
+
def rescue_action_in_public_with_airbrake(exception)
|
16
|
+
unless airbrake_ignore_user_agent?
|
17
|
+
error_id = Airbrake.notify_or_ignore(exception, airbrake_request_data)
|
18
|
+
request.env['airbrake.error_id'] = error_id
|
19
|
+
end
|
20
|
+
rescue_action_in_public_without_airbrake(exception)
|
21
|
+
end
|
22
|
+
|
23
|
+
def airbrake_ignore_user_agent? #:nodoc:
|
24
|
+
# Rails 1.2.6 doesn't have request.user_agent, so check for it here
|
25
|
+
user_agent = request.respond_to?(:user_agent) ? request.user_agent : request.env["HTTP_USER_AGENT"]
|
26
|
+
Airbrake.configuration.ignore_user_agent.flatten.any? { |ua| ua === user_agent }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module Airbrake
|
2
|
+
module Rails
|
3
|
+
module ControllerMethods
|
4
|
+
private
|
5
|
+
|
6
|
+
# This method should be used for sending manual notifications while you are still
|
7
|
+
# inside the controller. Otherwise it works like Airbrake.notify.
|
8
|
+
def notify_airbrake(hash_or_exception)
|
9
|
+
unless airbrake_local_request?
|
10
|
+
Airbrake.notify(hash_or_exception, airbrake_request_data)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def airbrake_local_request?
|
15
|
+
if defined?(::Rails.application.config)
|
16
|
+
::Rails.application.config.consider_all_requests_local || request.local?
|
17
|
+
else
|
18
|
+
consider_all_requests_local || local_request?
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def airbrake_ignore_user_agent? #:nodoc:
|
23
|
+
# Rails 1.2.6 doesn't have request.user_agent, so check for it here
|
24
|
+
user_agent = request.respond_to?(:user_agent) ? request.user_agent : request.env["HTTP_USER_AGENT"]
|
25
|
+
Airbrake.configuration.ignore_user_agent.flatten.any? { |ua| ua === user_agent }
|
26
|
+
end
|
27
|
+
|
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
|
+
|
37
|
+
def airbrake_filter_if_filtering(hash)
|
38
|
+
return hash if ! hash.is_a?(Hash)
|
39
|
+
|
40
|
+
if respond_to?(:filter_parameters)
|
41
|
+
filter_parameters(hash) rescue hash
|
42
|
+
else
|
43
|
+
hash
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def airbrake_session_data
|
48
|
+
if session.respond_to?(:to_hash)
|
49
|
+
session.to_hash
|
50
|
+
else
|
51
|
+
session.data
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def airbrake_request_url
|
56
|
+
url = "#{request.protocol}#{request.host}"
|
57
|
+
|
58
|
+
unless [80, 443].include?(request.port)
|
59
|
+
url << ":#{request.port}"
|
60
|
+
end
|
61
|
+
|
62
|
+
url << request.fullpath
|
63
|
+
url
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Airbrake
|
2
|
+
module Rails
|
3
|
+
module ErrorLookup
|
4
|
+
|
5
|
+
# Sets up an alias chain to catch exceptions when Rails does
|
6
|
+
def self.included(base) #:nodoc:
|
7
|
+
base.send(:alias_method, :rescue_action_locally_without_airbrake, :rescue_action_locally)
|
8
|
+
base.send(:alias_method, :rescue_action_locally, :rescue_action_locally_with_airbrake)
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def rescue_action_locally_with_airbrake(exception)
|
14
|
+
result = rescue_action_locally_without_airbrake(exception)
|
15
|
+
|
16
|
+
if Airbrake.configuration.development_lookup
|
17
|
+
path = File.join(File.dirname(__FILE__), '..', '..', 'templates', 'rescue.erb')
|
18
|
+
notice = Airbrake.build_lookup_hash_for(exception, airbrake_request_data)
|
19
|
+
|
20
|
+
result << @template.render(
|
21
|
+
:file => path,
|
22
|
+
:use_full_path => false,
|
23
|
+
:locals => { :host => Airbrake.configuration.host,
|
24
|
+
:api_key => Airbrake.configuration.api_key,
|
25
|
+
:notice => notice })
|
26
|
+
end
|
27
|
+
|
28
|
+
result
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Airbrake
|
2
|
+
module Rails
|
3
|
+
module JavascriptNotifier
|
4
|
+
def self.included(base) #:nodoc:
|
5
|
+
base.send :helper_method, :airbrake_javascript_notifier
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def airbrake_javascript_notifier
|
11
|
+
return unless Airbrake.configuration.public?
|
12
|
+
|
13
|
+
path = File.join File.dirname(__FILE__), '..', '..', 'templates', 'javascript_notifier.erb'
|
14
|
+
host = Airbrake.configuration.host.dup
|
15
|
+
port = Airbrake.configuration.port
|
16
|
+
host << ":#{port}" unless [80, 443].include?(port)
|
17
|
+
|
18
|
+
options = {
|
19
|
+
:file => path,
|
20
|
+
:layout => false,
|
21
|
+
:use_full_path => false,
|
22
|
+
:locals => {
|
23
|
+
:host => host,
|
24
|
+
:api_key => Airbrake.configuration.api_key,
|
25
|
+
:environment => Airbrake.configuration.environment_name,
|
26
|
+
:action_name => action_name,
|
27
|
+
:controller_name => controller_name,
|
28
|
+
:url => request.url
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
if @template
|
33
|
+
@template.render(options)
|
34
|
+
else
|
35
|
+
render_to_string(options)
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'airbrake'
|
2
|
+
require File.join(File.dirname(__FILE__), 'shared_tasks')
|
3
|
+
|
4
|
+
namespace :airbrake do
|
5
|
+
desc "Verify your gem installation by sending a test exception to the airbrake service"
|
6
|
+
task :test => [:environment] do
|
7
|
+
Rails.logger = Logger.new(STDOUT)
|
8
|
+
Rails.logger.level = Logger::DEBUG
|
9
|
+
Airbrake.configure(true) do |config|
|
10
|
+
config.logger = Rails.logger
|
11
|
+
end
|
12
|
+
|
13
|
+
require './app/controllers/application_controller'
|
14
|
+
|
15
|
+
class AirbrakeTestingException < RuntimeError; end
|
16
|
+
|
17
|
+
unless Airbrake.configuration.api_key
|
18
|
+
puts "Airbrake needs an API key configured! Check the README to see how to add it."
|
19
|
+
exit
|
20
|
+
end
|
21
|
+
|
22
|
+
Airbrake.configuration.development_environments = []
|
23
|
+
|
24
|
+
puts "Configuration:"
|
25
|
+
Airbrake.configuration.to_hash.each do |key, value|
|
26
|
+
puts sprintf("%25s: %s", key.to_s, value.inspect.slice(0, 55))
|
27
|
+
end
|
28
|
+
|
29
|
+
unless defined?(ApplicationController)
|
30
|
+
puts "No ApplicationController found"
|
31
|
+
exit
|
32
|
+
end
|
33
|
+
|
34
|
+
puts 'Setting up the Controller.'
|
35
|
+
class ApplicationController
|
36
|
+
# This is to bypass any filters that may prevent access to the action.
|
37
|
+
prepend_before_filter :test_airbrake
|
38
|
+
def test_airbrake
|
39
|
+
puts "Raising '#{exception_class.name}' to simulate application failure."
|
40
|
+
raise exception_class.new, 'Testing airbrake via "rake airbrake:test". If you can see this, it works.'
|
41
|
+
end
|
42
|
+
|
43
|
+
# def rescue_action(exception)
|
44
|
+
# rescue_action_in_public exception
|
45
|
+
# end
|
46
|
+
|
47
|
+
# Ensure we actually have an action to go to.
|
48
|
+
def verify; end
|
49
|
+
|
50
|
+
# def consider_all_requests_local
|
51
|
+
# false
|
52
|
+
# end
|
53
|
+
|
54
|
+
# def local_request?
|
55
|
+
# false
|
56
|
+
# end
|
57
|
+
|
58
|
+
def exception_class
|
59
|
+
exception_name = ENV['EXCEPTION'] || "AirbrakeTestingException"
|
60
|
+
Object.const_get(exception_name)
|
61
|
+
rescue
|
62
|
+
Object.const_set(exception_name, Class.new(Exception))
|
63
|
+
end
|
64
|
+
|
65
|
+
def logger
|
66
|
+
nil
|
67
|
+
end
|
68
|
+
end
|
69
|
+
class AirbrakeVerificationController < ApplicationController; end
|
70
|
+
|
71
|
+
Rails.application.routes_reloader.execute_if_updated
|
72
|
+
Rails.application.routes.draw do
|
73
|
+
match 'verify' => 'application#verify', :as => 'verify'
|
74
|
+
end
|
75
|
+
|
76
|
+
puts 'Processing request.'
|
77
|
+
env = Rack::MockRequest.env_for("/verify")
|
78
|
+
|
79
|
+
Rails.application.call(env)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'airbrake'
|
2
|
+
require 'rails'
|
3
|
+
|
4
|
+
module Airbrake
|
5
|
+
class Railtie < Rails::Railtie
|
6
|
+
rake_tasks do
|
7
|
+
require 'airbrake/rake_handler'
|
8
|
+
require "airbrake/rails3_tasks"
|
9
|
+
end
|
10
|
+
|
11
|
+
initializer "airbrake.use_rack_middleware" do |app|
|
12
|
+
app.config.middleware.use "Airbrake::Rack"
|
13
|
+
app.config.middleware.insert 0, "Airbrake::UserInformer"
|
14
|
+
end
|
15
|
+
|
16
|
+
config.after_initialize do
|
17
|
+
Airbrake.configure(true) do |config|
|
18
|
+
config.logger ||= Rails.logger
|
19
|
+
config.environment_name ||= Rails.env
|
20
|
+
config.project_root ||= Rails.root
|
21
|
+
config.framework = "Rails: #{::Rails::VERSION::STRING}"
|
22
|
+
end
|
23
|
+
|
24
|
+
if defined?(::ActionController::Base)
|
25
|
+
require 'airbrake/rails/javascript_notifier'
|
26
|
+
require 'airbrake/rails/controller_methods'
|
27
|
+
|
28
|
+
::ActionController::Base.send(:include, Airbrake::Rails::ControllerMethods)
|
29
|
+
::ActionController::Base.send(:include, Airbrake::Rails::JavascriptNotifier)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# Patch Rake::Application to handle errors with Airbrake
|
2
|
+
module Airbrake::RakeHandler
|
3
|
+
def self.included(klass)
|
4
|
+
klass.class_eval do
|
5
|
+
include Rake087Methods unless defined?(Rake::VERSION) && Rake::VERSION >= '0.9.0'
|
6
|
+
alias_method :display_error_message_without_airbrake, :display_error_message
|
7
|
+
alias_method :display_error_message, :display_error_message_with_airbrake
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def display_error_message_with_airbrake(ex)
|
12
|
+
if Airbrake.configuration.rescue_rake_exceptions ||
|
13
|
+
(Airbrake.configuration.rescue_rake_exceptions===nil && !self.tty_output?)
|
14
|
+
|
15
|
+
Airbrake.notify(ex, :component => reconstruct_command_line, :cgi_data => ENV)
|
16
|
+
end
|
17
|
+
|
18
|
+
display_error_message_without_airbrake(ex)
|
19
|
+
end
|
20
|
+
|
21
|
+
def reconstruct_command_line
|
22
|
+
"rake #{ARGV.join( ' ' )}"
|
23
|
+
end
|
24
|
+
|
25
|
+
# This module brings Rake 0.8.7 error handling to 0.9.0 standards
|
26
|
+
module Rake087Methods
|
27
|
+
# Method taken from Rake 0.9.0 source
|
28
|
+
#
|
29
|
+
# Provide standard exception handling for the given block.
|
30
|
+
def standard_exception_handling
|
31
|
+
begin
|
32
|
+
yield
|
33
|
+
rescue SystemExit => ex
|
34
|
+
# Exit silently with current status
|
35
|
+
raise
|
36
|
+
rescue OptionParser::InvalidOption => ex
|
37
|
+
$stderr.puts ex.message
|
38
|
+
exit(false)
|
39
|
+
rescue Exception => ex
|
40
|
+
# Exit with error message
|
41
|
+
display_error_message(ex)
|
42
|
+
exit(false)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# Method extracted from Rake 0.8.7 source
|
47
|
+
def display_error_message(ex)
|
48
|
+
$stderr.puts "#{name} aborted!"
|
49
|
+
$stderr.puts ex.message
|
50
|
+
if options.trace
|
51
|
+
$stderr.puts ex.backtrace.join("\n")
|
52
|
+
else
|
53
|
+
$stderr.puts ex.backtrace.find {|str| str =~ /#{@rakefile}/ } || ""
|
54
|
+
$stderr.puts "(See full trace by running task with --trace)"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
Rake.application.instance_eval do
|
61
|
+
class << self
|
62
|
+
include Airbrake::RakeHandler
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|