airbrake 4.3.8 → 5.0.0.rc.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/airbrake.rb +16 -185
- data/lib/airbrake/capistrano/tasks.rb +64 -0
- data/lib/airbrake/delayed_job/plugin.rb +48 -0
- data/lib/airbrake/rack/middleware.rb +45 -0
- data/lib/airbrake/rack/notice_builder.rb +80 -0
- data/lib/airbrake/rack/user.rb +51 -0
- data/lib/airbrake/rails/action_controller.rb +35 -0
- data/lib/airbrake/rails/active_job.rb +23 -0
- data/lib/airbrake/rails/active_record.rb +40 -0
- data/lib/airbrake/rails/railtie.rb +61 -0
- data/lib/airbrake/rake/task_ext.rb +61 -0
- data/lib/airbrake/rake/tasks.rb +93 -0
- data/lib/airbrake/resque/failure.rb +19 -0
- data/lib/airbrake/sidekiq/error_handler.rb +35 -0
- data/lib/airbrake/version.rb +4 -1
- data/lib/generators/airbrake_generator.rb +25 -0
- data/lib/generators/airbrake_initializer.rb.erb +55 -0
- data/spec/airbrake_spec.rb +0 -0
- data/spec/apps/rack/dummy_app.rb +17 -0
- data/spec/apps/rails/dummy_app.rb +150 -0
- data/spec/apps/rails/dummy_task.rake +20 -0
- data/spec/apps/rails/logs/32.log +13358 -0
- data/spec/apps/rails/logs/40.log +6854 -0
- data/spec/apps/rails/logs/41.log +3170 -0
- data/spec/apps/rails/logs/42.log +23919 -0
- data/spec/apps/rails/logs/50.log +10976 -0
- data/spec/apps/sinatra/dummy_app.rb +12 -0
- data/spec/integration/rack/rack_spec.rb +17 -0
- data/spec/integration/rails/rails_spec.rb +135 -0
- data/spec/integration/rails/rake_spec.rb +160 -0
- data/spec/integration/shared_examples/rack_examples.rb +106 -0
- data/spec/integration/sinatra/sinatra_spec.rb +15 -0
- data/spec/spec_helper.rb +127 -0
- data/spec/unit/rack/middleware_spec.rb +80 -0
- data/spec/unit/rack/notice_builder_spec.rb +35 -0
- data/spec/unit/rack/user_spec.rb +78 -0
- data/spec/unit/rake/tasks_spec.rb +40 -0
- data/spec/unit/sidekiq/error_handler_spec.rb +29 -0
- metadata +110 -325
- data/CHANGELOG +0 -1716
- data/Gemfile +0 -3
- data/Guardfile +0 -6
- data/INSTALL +0 -20
- data/LICENSE +0 -61
- data/README.md +0 -148
- data/README_FOR_HEROKU_ADDON.md +0 -102
- data/Rakefile +0 -179
- data/TESTED_AGAINST +0 -7
- data/airbrake.gemspec +0 -41
- data/bin/airbrake +0 -12
- data/features/metal.feature +0 -34
- data/features/rack.feature +0 -60
- data/features/rails.feature +0 -324
- data/features/rake.feature +0 -33
- data/features/sinatra.feature +0 -126
- data/features/step_definitions/file_steps.rb +0 -14
- data/features/step_definitions/rack_steps.rb +0 -27
- data/features/step_definitions/rails_application_steps.rb +0 -267
- data/features/step_definitions/rake_steps.rb +0 -22
- data/features/support/airbrake_shim.rb.template +0 -11
- data/features/support/aruba.rb +0 -5
- data/features/support/env.rb +0 -39
- data/features/support/matchers.rb +0 -35
- data/features/support/rails.rb +0 -156
- data/features/support/rake/Rakefile +0 -77
- data/features/user_informer.feature +0 -57
- data/generators/airbrake/airbrake_generator.rb +0 -94
- data/generators/airbrake/lib/insert_commands.rb +0 -34
- data/generators/airbrake/lib/rake_commands.rb +0 -24
- data/generators/airbrake/templates/airbrake_tasks.rake +0 -25
- data/generators/airbrake/templates/capistrano_hook.rb +0 -6
- data/generators/airbrake/templates/initializer.rb +0 -4
- data/install.rb +0 -1
- data/lib/airbrake/backtrace.rb +0 -103
- data/lib/airbrake/capistrano.rb +0 -103
- data/lib/airbrake/capistrano3.rb +0 -3
- data/lib/airbrake/cli/client.rb +0 -76
- data/lib/airbrake/cli/options.rb +0 -45
- data/lib/airbrake/cli/printer.rb +0 -33
- data/lib/airbrake/cli/project.rb +0 -17
- data/lib/airbrake/cli/project_factory.rb +0 -33
- data/lib/airbrake/cli/runner.rb +0 -49
- data/lib/airbrake/cli/validator.rb +0 -8
- data/lib/airbrake/configuration.rb +0 -366
- data/lib/airbrake/jobs/send_job.rb +0 -7
- data/lib/airbrake/notice.rb +0 -411
- data/lib/airbrake/rack.rb +0 -64
- data/lib/airbrake/rails.rb +0 -45
- data/lib/airbrake/rails/action_controller_catcher.rb +0 -32
- data/lib/airbrake/rails/controller_methods.rb +0 -146
- data/lib/airbrake/rails/error_lookup.rb +0 -35
- data/lib/airbrake/rails/middleware.rb +0 -63
- data/lib/airbrake/rails3_tasks.rb +0 -126
- data/lib/airbrake/railtie.rb +0 -46
- data/lib/airbrake/rake_handler.rb +0 -75
- data/lib/airbrake/response.rb +0 -29
- data/lib/airbrake/sender.rb +0 -213
- data/lib/airbrake/shared_tasks.rb +0 -59
- data/lib/airbrake/sidekiq.rb +0 -8
- data/lib/airbrake/sinatra.rb +0 -40
- data/lib/airbrake/tasks.rb +0 -81
- data/lib/airbrake/tasks/airbrake.cap +0 -28
- data/lib/airbrake/user_informer.rb +0 -36
- data/lib/airbrake/utils/params_cleaner.rb +0 -141
- data/lib/airbrake/utils/rack_filters.rb +0 -45
- data/lib/airbrake_tasks.rb +0 -62
- data/lib/rails/generators/airbrake/airbrake_generator.rb +0 -155
- data/lib/templates/rescue.erb +0 -91
- data/rails/init.rb +0 -1
- data/resources/README.md +0 -34
- data/resources/airbrake_2_4.xsd +0 -89
- data/resources/airbrake_3_0.json +0 -52
- data/resources/ca-bundle.crt +0 -3376
- data/script/integration_test.rb +0 -35
- data/test/airbrake_tasks_test.rb +0 -161
- data/test/backtrace_test.rb +0 -215
- data/test/capistrano_test.rb +0 -44
- data/test/configuration_test.rb +0 -303
- data/test/controller_methods_test.rb +0 -230
- data/test/helper.rb +0 -233
- data/test/integration.rb +0 -13
- data/test/integration/catcher_test.rb +0 -371
- data/test/logger_test.rb +0 -79
- data/test/notice_test.rb +0 -494
- data/test/notifier_test.rb +0 -288
- data/test/params_cleaner_test.rb +0 -204
- data/test/rack_test.rb +0 -62
- data/test/rails_initializer_test.rb +0 -36
- data/test/recursion_test.rb +0 -10
- data/test/response_test.rb +0 -18
- data/test/sender_test.rb +0 -335
- data/test/support/response_shim.xml +0 -4
- data/test/user_informer_test.rb +0 -29
data/lib/airbrake/rails.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
require 'airbrake'
|
2
|
-
require 'airbrake/rails/controller_methods'
|
3
|
-
require 'airbrake/rails/action_controller_catcher'
|
4
|
-
require 'airbrake/rails/error_lookup'
|
5
|
-
|
6
|
-
module Airbrake
|
7
|
-
module Rails
|
8
|
-
def self.initialize
|
9
|
-
if defined?(ActionController::Base)
|
10
|
-
ActionController::Base.send(:include, Airbrake::Rails::ActionControllerCatcher)
|
11
|
-
ActionController::Base.send(:include, Airbrake::Rails::ErrorLookup)
|
12
|
-
ActionController::Base.send(:include, Airbrake::Rails::ControllerMethods)
|
13
|
-
end
|
14
|
-
|
15
|
-
rails_logger = if defined?(::Rails.logger)
|
16
|
-
::Rails.logger
|
17
|
-
elsif defined?(RAILS_DEFAULT_LOGGER)
|
18
|
-
RAILS_DEFAULT_LOGGER
|
19
|
-
end
|
20
|
-
|
21
|
-
if defined?(::Rails.configuration) && ::Rails.configuration.respond_to?(:middleware)
|
22
|
-
if defined?(::ActionController::Failsafe)
|
23
|
-
::Rails.configuration.middleware.insert_after 'ActionController::Failsafe',
|
24
|
-
Airbrake::Rack
|
25
|
-
end
|
26
|
-
if defined?(::Rack::Lock)
|
27
|
-
::Rails.configuration.middleware.insert_after 'Rack::Lock',
|
28
|
-
Airbrake::UserInformer
|
29
|
-
else
|
30
|
-
::Rails.configuration.middleware.insert_before 'Rack::Runtime',
|
31
|
-
Airbrake::UserInformer
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
Airbrake.configure(true) do |config|
|
36
|
-
config.logger = rails_logger
|
37
|
-
config.environment_name = defined?(::Rails.env) && ::Rails.env || defined?(RAILS_ENV) && RAILS_ENV
|
38
|
-
config.project_root = defined?(::Rails.root) && ::Rails.root || defined?(RAILS_ROOT) && RAILS_ROOT
|
39
|
-
config.framework = defined?(::Rails.version) && "Rails: #{::Rails.version}" || defined?(::Rails::VERSION::STRING) && "Rails: #{::Rails::VERSION::STRING}"
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
Airbrake::Rails.initialize
|
@@ -1,32 +0,0 @@
|
|
1
|
-
module Airbrake
|
2
|
-
module Rails
|
3
|
-
module ActionControllerCatcher
|
4
|
-
|
5
|
-
# Sets up an alias chain to catch exceptions for Rails 2
|
6
|
-
def self.included(base) #:nodoc:
|
7
|
-
if base.method_defined?(:rescue_action_in_public)
|
8
|
-
base.send(:alias_method, :rescue_action_in_public_without_airbrake, :rescue_action_in_public)
|
9
|
-
base.send(:alias_method, :rescue_action_in_public, :rescue_action_in_public_with_airbrake)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
private
|
14
|
-
|
15
|
-
# Overrides the rescue_action method in ActionController::Base, but does not inhibit
|
16
|
-
# any custom processing that is defined with Rails 2's exception helpers.
|
17
|
-
def rescue_action_in_public_with_airbrake(exception)
|
18
|
-
unless airbrake_ignore_user_agent?
|
19
|
-
error_id = Airbrake.notify_or_ignore(exception, airbrake_request_data)
|
20
|
-
request.env['airbrake.error_id'] = error_id
|
21
|
-
end
|
22
|
-
rescue_action_in_public_without_airbrake(exception)
|
23
|
-
end
|
24
|
-
|
25
|
-
def airbrake_ignore_user_agent? #:nodoc:
|
26
|
-
# Rails 1.2.6 doesn't have request.user_agent, so check for it here
|
27
|
-
user_agent = request.respond_to?(:user_agent) ? request.user_agent : request.env["HTTP_USER_AGENT"]
|
28
|
-
Airbrake.configuration.ignore_user_agent.flatten.any? { |ua| ua === user_agent }
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,146 +0,0 @@
|
|
1
|
-
module Airbrake
|
2
|
-
module Rails
|
3
|
-
module ControllerMethods
|
4
|
-
|
5
|
-
SLASH = "/"
|
6
|
-
|
7
|
-
def airbrake_request_data
|
8
|
-
{
|
9
|
-
:parameters => airbrake_filter_if_filtering(to_hash(params)),
|
10
|
-
:session_data => airbrake_filter_if_filtering(airbrake_session_data),
|
11
|
-
:controller => params[:controller],
|
12
|
-
:action => params[:action],
|
13
|
-
:url => airbrake_request_url,
|
14
|
-
:cgi_data => airbrake_filter_if_filtering(request.env),
|
15
|
-
:user => airbrake_current_user
|
16
|
-
}
|
17
|
-
end
|
18
|
-
|
19
|
-
private
|
20
|
-
|
21
|
-
def to_hash(params)
|
22
|
-
# Rails <= 4
|
23
|
-
return params.to_hash if params.respond_to?(:to_hash)
|
24
|
-
|
25
|
-
# Rails >= 5
|
26
|
-
params.to_unsafe_h
|
27
|
-
end
|
28
|
-
|
29
|
-
# This method should be used for sending manual notifications while you are still
|
30
|
-
# inside the controller. Otherwise it works like Airbrake.notify.
|
31
|
-
def notify_airbrake(hash_or_exception)
|
32
|
-
unless airbrake_local_request?
|
33
|
-
Airbrake.notify_or_ignore(hash_or_exception, airbrake_request_data)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def airbrake_local_request?
|
38
|
-
if defined?(::Rails.application.config)
|
39
|
-
::Rails.application.config.consider_all_requests_local || (request.local? && (!request.env["HTTP_X_FORWARDED_FOR"]))
|
40
|
-
else
|
41
|
-
consider_all_requests_local || (local_request? && (!request.env["HTTP_X_FORWARDED_FOR"]))
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def airbrake_ignore_user_agent? #:nodoc:
|
46
|
-
# Rails 1.2.6 doesn't have request.user_agent, so check for it here
|
47
|
-
user_agent = request.respond_to?(:user_agent) ? request.user_agent : request.env["HTTP_USER_AGENT"]
|
48
|
-
Airbrake.configuration.ignore_user_agent.flatten.any? { |ua| ua === user_agent }
|
49
|
-
end
|
50
|
-
|
51
|
-
|
52
|
-
def airbrake_filter_if_filtering(hash)
|
53
|
-
return hash if ! hash.is_a?(Hash)
|
54
|
-
|
55
|
-
if respond_to?(:filter_parameters) # Rails 2
|
56
|
-
filter_parameters(hash)
|
57
|
-
elsif rails_3_or_4?
|
58
|
-
filter_rails3_parameters(hash)
|
59
|
-
else
|
60
|
-
hash
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def rails_3_or_4?
|
65
|
-
defined?(::Rails.version) && ::Rails.version =~ /\A[34]/
|
66
|
-
end
|
67
|
-
|
68
|
-
def filter_rails3_parameters(hash)
|
69
|
-
ActionDispatch::Http::ParameterFilter.new(
|
70
|
-
::Rails.application.config.filter_parameters
|
71
|
-
).filter(recursive_stringify_keys(hash))
|
72
|
-
end
|
73
|
-
|
74
|
-
def recursive_stringify_keys(hash)
|
75
|
-
hash = hash.stringify_keys
|
76
|
-
hash.each do |k, v|
|
77
|
-
if v.is_a?(Hash)
|
78
|
-
hash[k] = v.respond_to?(:stringify_keys) ? recursive_stringify_keys(v) : nil # Rack::Session::Abstract::SessionHash has a stringify_keys method we should not call
|
79
|
-
end
|
80
|
-
end
|
81
|
-
hash
|
82
|
-
end
|
83
|
-
|
84
|
-
def airbrake_session_data
|
85
|
-
if session
|
86
|
-
if session.respond_to?(:to_hash)
|
87
|
-
session.to_hash
|
88
|
-
else
|
89
|
-
session.data
|
90
|
-
end
|
91
|
-
else
|
92
|
-
{:session => 'no session found'}
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
def airbrake_request_url
|
97
|
-
url = "#{request.protocol}#{request.host}"
|
98
|
-
|
99
|
-
unless [80, 443].include?(request.port)
|
100
|
-
url << ":#{request.port}"
|
101
|
-
end
|
102
|
-
|
103
|
-
unless request.fullpath[0] == SLASH
|
104
|
-
url << SLASH
|
105
|
-
end
|
106
|
-
|
107
|
-
url << request.fullpath
|
108
|
-
end
|
109
|
-
|
110
|
-
def airbrake_current_user
|
111
|
-
user = fetch_user
|
112
|
-
|
113
|
-
if user
|
114
|
-
Airbrake.configuration.user_attributes.map(&:to_sym).inject({}) do |hsh, attr|
|
115
|
-
begin
|
116
|
-
hsh[attr] = user.send(attr) if user.respond_to? attr
|
117
|
-
hsh
|
118
|
-
rescue
|
119
|
-
hsh
|
120
|
-
end
|
121
|
-
end
|
122
|
-
else
|
123
|
-
{}
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
def fetch_user
|
128
|
-
if defined?(current_user)
|
129
|
-
current_user
|
130
|
-
elsif defined?(current_member)
|
131
|
-
current_member
|
132
|
-
else
|
133
|
-
nil
|
134
|
-
end
|
135
|
-
rescue
|
136
|
-
nil
|
137
|
-
ensure
|
138
|
-
# The Airbrake middleware is first in the chain, before ActiveRecord::ConnectionAdapters::ConnectionManagement
|
139
|
-
# kicks in to do its thing. This can cause the connection pool to run out of connections.
|
140
|
-
if defined?(ActiveRecord::Base) && ActiveRecord::Base.respond_to?(:clear_active_connections!)
|
141
|
-
ActiveRecord::Base.clear_active_connections!
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
145
|
-
end
|
146
|
-
end
|
@@ -1,35 +0,0 @@
|
|
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
|
-
if base.method_defined?(:rescue_action_locally)
|
8
|
-
base.send(:alias_method, :rescue_action_locally_without_airbrake, :rescue_action_locally)
|
9
|
-
base.send(:alias_method, :rescue_action_locally, :rescue_action_locally_with_airbrake)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
private
|
14
|
-
|
15
|
-
def rescue_action_locally_with_airbrake(exception)
|
16
|
-
result = rescue_action_locally_without_airbrake(exception)
|
17
|
-
|
18
|
-
if Airbrake.configuration.development_lookup
|
19
|
-
path = File.join(File.dirname(__FILE__), '..', '..', 'templates', 'rescue.erb')
|
20
|
-
notice = Airbrake.build_lookup_hash_for(exception, airbrake_request_data)
|
21
|
-
|
22
|
-
result << @template.render(
|
23
|
-
:file => path,
|
24
|
-
:use_full_path => false,
|
25
|
-
:locals => { :host => Airbrake.configuration.host,
|
26
|
-
:api_key => Airbrake.configuration.api_key,
|
27
|
-
:notice => notice })
|
28
|
-
end
|
29
|
-
|
30
|
-
result
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
@@ -1,63 +0,0 @@
|
|
1
|
-
module Airbrake
|
2
|
-
module Rails
|
3
|
-
# Rack middleware for Rails applications. Any errors raised by the upstream
|
4
|
-
# application will be delivered to Airbrake and re-raised.
|
5
|
-
#
|
6
|
-
class Middleware
|
7
|
-
def initialize(app)
|
8
|
-
@app = app
|
9
|
-
end
|
10
|
-
|
11
|
-
def call(env)
|
12
|
-
begin
|
13
|
-
response = @app.call(env)
|
14
|
-
rescue Exception => exception
|
15
|
-
env['airbrake.error_id'] = notify_airbrake(env, exception)
|
16
|
-
raise exception
|
17
|
-
end
|
18
|
-
|
19
|
-
if framework_exception = env["action_dispatch.exception"]
|
20
|
-
env["airbrake.error_id"] = notify_airbrake(env, framework_exception)
|
21
|
-
end
|
22
|
-
|
23
|
-
response
|
24
|
-
end
|
25
|
-
|
26
|
-
private
|
27
|
-
|
28
|
-
def controller(env)
|
29
|
-
env["action_controller.instance"]
|
30
|
-
end
|
31
|
-
|
32
|
-
def after_airbrake_handler(env, exception)
|
33
|
-
if controller(env).respond_to?(:rescue_action_in_public_without_airbrake)
|
34
|
-
controller(env).rescue_action_in_public_without_airbrake(exception)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def notify_airbrake(env, exception)
|
39
|
-
unless ignored_user_agent? env
|
40
|
-
error_id = Airbrake.notify_or_ignore(exception, request_data(env))
|
41
|
-
after_airbrake_handler(env, exception)
|
42
|
-
error_id
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def request_data(env)
|
47
|
-
if controller(env).respond_to?(:airbrake_request_data)
|
48
|
-
controller(env).airbrake_request_data
|
49
|
-
else
|
50
|
-
{:rack_env => env}
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def ignored_user_agent?(env)
|
55
|
-
true if Airbrake.
|
56
|
-
configuration.
|
57
|
-
ignore_user_agent.
|
58
|
-
flatten.
|
59
|
-
any? { |ua| ua === env['HTTP_USER_AGENT'] }
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
@@ -1,126 +0,0 @@
|
|
1
|
-
require 'airbrake'
|
2
|
-
require File.join(File.dirname(__FILE__), 'shared_tasks')
|
3
|
-
|
4
|
-
def stub_rake_exception_handling!
|
5
|
-
# Override error handling in Rake so we don't clutter STDERR
|
6
|
-
# with unnecesarry stack trace
|
7
|
-
Rake.application.instance_eval do
|
8
|
-
class << self
|
9
|
-
def display_error_message_silent(exception)
|
10
|
-
puts exception
|
11
|
-
end
|
12
|
-
alias_method :display_error_message_old, :display_error_message
|
13
|
-
alias_method :display_error_message, :display_error_message_silent
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def unstub_rake_exception_handling!
|
19
|
-
# Turns Rake exception handling back to normal
|
20
|
-
Rake.application.instance_eval do
|
21
|
-
class << self
|
22
|
-
def display_error_message_silent(exception)
|
23
|
-
display_error_message_old(exception)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
namespace :airbrake do
|
30
|
-
desc "Verify your gem installation by sending a test exception to the airbrake service"
|
31
|
-
task :test => [:environment] do
|
32
|
-
|
33
|
-
stub_rake_exception_handling!
|
34
|
-
|
35
|
-
Rails.logger = defined?(ActiveSupport::TaggedLogging) ?
|
36
|
-
ActiveSupport::TaggedLogging.new(Logger.new(STDOUT)) :
|
37
|
-
Logger.new(STDOUT)
|
38
|
-
|
39
|
-
def wait_for_threads
|
40
|
-
# if using multiple threads, we have to wait for
|
41
|
-
# them to finish
|
42
|
-
if GirlFriday.status.empty?
|
43
|
-
Thread.list.each do |thread|
|
44
|
-
thread.join unless thread == Thread.current
|
45
|
-
end
|
46
|
-
else
|
47
|
-
GirlFriday.shutdown!
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
# Sets up verbose logging
|
52
|
-
Rails.logger.level = Logger::DEBUG
|
53
|
-
Airbrake.configure(true) do |config|
|
54
|
-
config.logger = Rails.logger
|
55
|
-
end
|
56
|
-
|
57
|
-
# Override Rails exception middleware, so we stop cluttering STDOUT
|
58
|
-
# with stack trace from Rails
|
59
|
-
class ActionDispatch::DebugExceptions; def call(env); @app.call(env); end; end
|
60
|
-
class ActionDispatch::ShowExceptions; def call(env); @app.call(env); end; end
|
61
|
-
|
62
|
-
require './app/controllers/application_controller'
|
63
|
-
|
64
|
-
class AirbrakeTestingException < RuntimeError; end
|
65
|
-
|
66
|
-
# Checks if api_key is set
|
67
|
-
unless Airbrake.configuration.api_key
|
68
|
-
puts "Airbrake needs an API key configured! Check the README to see how to add it."
|
69
|
-
exit
|
70
|
-
end
|
71
|
-
|
72
|
-
# Enables Airbrake reporting on all environments,
|
73
|
-
# so we don't have to worry about invoking the task in production
|
74
|
-
Airbrake.configuration.development_environments = []
|
75
|
-
|
76
|
-
puts "Configuration:"
|
77
|
-
Airbrake.configuration.to_hash.each do |key, value|
|
78
|
-
puts sprintf("%25s: %s", key.to_s, value.inspect.slice(0, 55))
|
79
|
-
end
|
80
|
-
|
81
|
-
unless defined?(ApplicationController)
|
82
|
-
puts "No ApplicationController found"
|
83
|
-
exit
|
84
|
-
end
|
85
|
-
|
86
|
-
puts 'Setting up the Controller.'
|
87
|
-
class ApplicationController
|
88
|
-
# This is to bypass any filters that may prevent access to the action.
|
89
|
-
prepend_before_filter :test_airbrake
|
90
|
-
def test_airbrake
|
91
|
-
puts "Raising '#{exception_class.name}' to simulate application failure."
|
92
|
-
raise exception_class.new, "\nTesting airbrake via \"rake airbrake:test\"."\
|
93
|
-
" If you can see this, it works."
|
94
|
-
end
|
95
|
-
|
96
|
-
# Ensure we actually have an action to go to.
|
97
|
-
def verify; end
|
98
|
-
|
99
|
-
def exception_class
|
100
|
-
exception_name = ENV['EXCEPTION'] || "AirbrakeTestingException"
|
101
|
-
Object.const_get(exception_name)
|
102
|
-
rescue
|
103
|
-
Object.const_set(exception_name, Class.new(Exception))
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
Rails.application.routes.draw do
|
108
|
-
get 'verify' => 'application#verify', :as => 'verify', :via => :get
|
109
|
-
end
|
110
|
-
|
111
|
-
puts 'Processing request.'
|
112
|
-
|
113
|
-
config = Rails.application.config
|
114
|
-
protocol = (config.respond_to?(:force_ssl) && config.force_ssl) ? 'https' : 'http'
|
115
|
-
|
116
|
-
env = Rack::MockRequest.env_for("#{protocol}://www.example.com/verify")
|
117
|
-
env['REMOTE_ADDR'] = '127.0.0.1'
|
118
|
-
|
119
|
-
Rails.application.call(env)
|
120
|
-
|
121
|
-
wait_for_threads if defined? GirlFriday
|
122
|
-
|
123
|
-
unstub_rake_exception_handling!
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|