airbrake 3.1.6 → 11.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/airbrake.rb +23 -150
- data/lib/airbrake/capistrano.rb +6 -42
- data/lib/airbrake/capistrano/capistrano2.rb +40 -0
- data/lib/airbrake/capistrano/capistrano3.rb +23 -0
- data/lib/airbrake/delayed_job.rb +66 -0
- data/lib/airbrake/logger.rb +103 -0
- data/lib/airbrake/rack.rb +30 -45
- data/lib/airbrake/rack/context_filter.rb +65 -0
- data/lib/airbrake/rack/http_headers_filter.rb +44 -0
- data/lib/airbrake/rack/http_params_filter.rb +27 -0
- data/lib/airbrake/rack/instrumentable.rb +136 -0
- data/lib/airbrake/rack/middleware.rb +102 -0
- data/lib/airbrake/rack/request_body_filter.rb +33 -0
- data/lib/airbrake/rack/request_store.rb +34 -0
- data/lib/airbrake/rack/route_filter.rb +51 -0
- data/lib/airbrake/rack/session_filter.rb +25 -0
- data/lib/airbrake/rack/user.rb +74 -0
- data/lib/airbrake/rack/user_filter.rb +25 -0
- data/lib/airbrake/rails.rb +25 -31
- data/lib/airbrake/rails/action_cable.rb +35 -0
- data/lib/airbrake/rails/action_cable/notify_callback.rb +22 -0
- data/lib/airbrake/rails/action_controller.rb +40 -0
- data/lib/airbrake/rails/action_controller_notify_subscriber.rb +32 -0
- data/lib/airbrake/rails/action_controller_performance_breakdown_subscriber.rb +51 -0
- data/lib/airbrake/rails/action_controller_route_subscriber.rb +33 -0
- data/lib/airbrake/rails/active_job.rb +50 -0
- data/lib/airbrake/rails/active_record.rb +36 -0
- data/lib/airbrake/rails/active_record_subscriber.rb +46 -0
- data/lib/airbrake/rails/app.rb +78 -0
- data/lib/airbrake/rails/backtrace_cleaner.rb +23 -0
- data/lib/airbrake/rails/curb.rb +32 -0
- data/lib/airbrake/rails/event.rb +81 -0
- data/lib/airbrake/rails/excon_subscriber.rb +25 -0
- data/lib/airbrake/rails/http.rb +14 -0
- data/lib/airbrake/rails/http_client.rb +16 -0
- data/lib/airbrake/rails/net_http.rb +18 -0
- data/lib/airbrake/rails/railtie.rb +151 -0
- data/lib/airbrake/rails/typhoeus.rb +16 -0
- data/lib/airbrake/rake.rb +65 -0
- data/lib/airbrake/rake/tasks.rb +112 -0
- data/lib/airbrake/resque.rb +61 -0
- data/lib/airbrake/shoryuken.rb +54 -0
- data/lib/airbrake/sidekiq.rb +55 -0
- data/lib/airbrake/sidekiq/retryable_jobs_filter.rb +53 -0
- data/lib/airbrake/sneakers.rb +72 -0
- data/lib/airbrake/version.rb +5 -1
- data/lib/generators/airbrake_generator.rb +25 -0
- data/lib/generators/airbrake_initializer.rb.erb +80 -0
- metadata +206 -259
- data/CHANGELOG +0 -944
- data/Gemfile +0 -3
- data/Guardfile +0 -6
- data/INSTALL +0 -20
- data/MIT-LICENSE +0 -22
- data/README.md +0 -556
- data/README_FOR_HEROKU_ADDON.md +0 -94
- data/Rakefile +0 -223
- data/SUPPORTED_RAILS_VERSIONS +0 -38
- data/TESTING.md +0 -41
- data/airbrake.gemspec +0 -40
- data/bin/airbrake +0 -12
- data/features/metal.feature +0 -18
- data/features/rack.feature +0 -60
- data/features/rails.feature +0 -272
- data/features/rails_with_js_notifier.feature +0 -97
- data/features/rake.feature +0 -27
- data/features/sinatra.feature +0 -29
- data/features/step_definitions/file_steps.rb +0 -10
- data/features/step_definitions/metal_steps.rb +0 -23
- data/features/step_definitions/rack_steps.rb +0 -23
- data/features/step_definitions/rails_application_steps.rb +0 -478
- data/features/step_definitions/rake_steps.rb +0 -17
- data/features/support/airbrake_shim.rb.template +0 -16
- data/features/support/env.rb +0 -18
- data/features/support/matchers.rb +0 -35
- data/features/support/rails.rb +0 -201
- data/features/support/rake/Rakefile +0 -68
- data/features/support/terminal.rb +0 -107
- data/features/user_informer.feature +0 -63
- 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 -6
- data/install.rb +0 -1
- data/lib/airbrake/backtrace.rb +0 -108
- data/lib/airbrake/cli/client.rb +0 -68
- data/lib/airbrake/cli/options.rb +0 -41
- data/lib/airbrake/cli/printer.rb +0 -30
- data/lib/airbrake/cli/project.rb +0 -17
- data/lib/airbrake/cli/project_factory.rb +0 -36
- data/lib/airbrake/cli/runner.rb +0 -48
- data/lib/airbrake/cli/validator.rb +0 -8
- data/lib/airbrake/configuration.rb +0 -311
- data/lib/airbrake/extensions/blank.rb +0 -73
- data/lib/airbrake/notice.rb +0 -390
- data/lib/airbrake/rails/action_controller_catcher.rb +0 -30
- data/lib/airbrake/rails/controller_methods.rb +0 -87
- data/lib/airbrake/rails/error_lookup.rb +0 -33
- data/lib/airbrake/rails/javascript_notifier.rb +0 -47
- data/lib/airbrake/rails/middleware/exceptions_catcher.rb +0 -33
- data/lib/airbrake/rails3_tasks.rb +0 -98
- data/lib/airbrake/railtie.rb +0 -48
- data/lib/airbrake/rake_handler.rb +0 -71
- data/lib/airbrake/sender.rb +0 -128
- data/lib/airbrake/shared_tasks.rb +0 -47
- data/lib/airbrake/tasks.rb +0 -83
- data/lib/airbrake/user_informer.rb +0 -27
- data/lib/airbrake_tasks.rb +0 -64
- data/lib/rails/generators/airbrake/airbrake_generator.rb +0 -100
- data/lib/templates/javascript_notifier.erb +0 -15
- data/lib/templates/rescue.erb +0 -91
- data/rails/init.rb +0 -1
- data/resources/README.md +0 -34
- data/resources/ca-bundle.crt +0 -3376
- data/script/integration_test.rb +0 -38
- data/test/airbrake_2_3.xsd +0 -88
- data/test/airbrake_tasks_test.rb +0 -170
- data/test/backtrace_test.rb +0 -162
- data/test/capistrano_test.rb +0 -34
- data/test/catcher_test.rb +0 -333
- data/test/configuration_test.rb +0 -233
- data/test/helper.rb +0 -263
- data/test/javascript_notifier_test.rb +0 -51
- data/test/logger_test.rb +0 -79
- data/test/notice_test.rb +0 -490
- data/test/notifier_test.rb +0 -276
- data/test/rack_test.rb +0 -58
- data/test/rails_initializer_test.rb +0 -36
- data/test/recursion_test.rb +0 -10
- data/test/sender_test.rb +0 -288
- data/test/user_informer_test.rb +0 -29
data/lib/airbrake/sender.rb
DELETED
@@ -1,128 +0,0 @@
|
|
1
|
-
module Airbrake
|
2
|
-
# Sends out the notice to Airbrake
|
3
|
-
class Sender
|
4
|
-
|
5
|
-
NOTICES_URI = '/notifier_api/v2/notices/'.freeze
|
6
|
-
HTTP_ERRORS = [Timeout::Error,
|
7
|
-
Errno::EINVAL,
|
8
|
-
Errno::ECONNRESET,
|
9
|
-
EOFError,
|
10
|
-
Net::HTTPBadResponse,
|
11
|
-
Net::HTTPHeaderSyntaxError,
|
12
|
-
Net::ProtocolError,
|
13
|
-
Errno::ECONNREFUSED].freeze
|
14
|
-
|
15
|
-
def initialize(options = {})
|
16
|
-
[ :proxy_host,
|
17
|
-
:proxy_port,
|
18
|
-
:proxy_user,
|
19
|
-
:proxy_pass,
|
20
|
-
:protocol,
|
21
|
-
:host,
|
22
|
-
:port,
|
23
|
-
:secure,
|
24
|
-
:use_system_ssl_cert_chain,
|
25
|
-
:http_open_timeout,
|
26
|
-
:http_read_timeout
|
27
|
-
].each do |option|
|
28
|
-
instance_variable_set("@#{option}", options[option])
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
# Sends the notice data off to Airbrake for processing.
|
33
|
-
#
|
34
|
-
# @param [Notice or String] notice The notice to be sent off
|
35
|
-
def send_to_airbrake(notice)
|
36
|
-
data = notice.respond_to?(:to_xml) ? notice.to_xml : notice
|
37
|
-
http = setup_http_connection
|
38
|
-
|
39
|
-
response = begin
|
40
|
-
http.post(url.path, data, HEADERS)
|
41
|
-
rescue *HTTP_ERRORS => e
|
42
|
-
log :level => :error,
|
43
|
-
:message => "Unable to contact the Airbrake server. HTTP Error=#{e}"
|
44
|
-
nil
|
45
|
-
end
|
46
|
-
|
47
|
-
case response
|
48
|
-
when Net::HTTPSuccess then
|
49
|
-
log :level => :info,
|
50
|
-
:message => "Success: #{response.class}",
|
51
|
-
:response => response
|
52
|
-
else
|
53
|
-
log :level => :error,
|
54
|
-
:message => "Failure: #{response.class}",
|
55
|
-
:response => response,
|
56
|
-
:notice => notice
|
57
|
-
end
|
58
|
-
|
59
|
-
if response && response.respond_to?(:body)
|
60
|
-
error_id = response.body.match(%r{<id[^>]*>(.*?)</id>})
|
61
|
-
error_id[1] if error_id
|
62
|
-
end
|
63
|
-
rescue => e
|
64
|
-
log :level => :error,
|
65
|
-
:message => "[Airbrake::Sender#send_to_airbrake] Cannot send notification. Error: #{e.class}" +
|
66
|
-
" - #{e.message}\nBacktrace:\n#{e.backtrace.join("\n\t")}"
|
67
|
-
|
68
|
-
nil
|
69
|
-
end
|
70
|
-
|
71
|
-
attr_reader :proxy_host,
|
72
|
-
:proxy_port,
|
73
|
-
:proxy_user,
|
74
|
-
:proxy_pass,
|
75
|
-
:protocol,
|
76
|
-
:host,
|
77
|
-
:port,
|
78
|
-
:secure,
|
79
|
-
:use_system_ssl_cert_chain,
|
80
|
-
:http_open_timeout,
|
81
|
-
:http_read_timeout
|
82
|
-
|
83
|
-
alias_method :secure?, :secure
|
84
|
-
alias_method :use_system_ssl_cert_chain?, :use_system_ssl_cert_chain
|
85
|
-
|
86
|
-
private
|
87
|
-
|
88
|
-
def url
|
89
|
-
URI.parse("#{protocol}://#{host}:#{port}").merge(NOTICES_URI)
|
90
|
-
end
|
91
|
-
|
92
|
-
def log(opts = {})
|
93
|
-
opts[:logger].send opts[:level], LOG_PREFIX + opts[:message] if opts[:logger]
|
94
|
-
Airbrake.report_environment_info
|
95
|
-
Airbrake.report_response_body(opts[:response].body) if opts[:response] && opts[:response].respond_to?(:body)
|
96
|
-
Airbrake.report_notice(opts[:notice]) if opts[:notice]
|
97
|
-
end
|
98
|
-
|
99
|
-
def logger
|
100
|
-
Airbrake.logger
|
101
|
-
end
|
102
|
-
|
103
|
-
def setup_http_connection
|
104
|
-
http =
|
105
|
-
Net::HTTP::Proxy(proxy_host, proxy_port, proxy_user, proxy_pass).
|
106
|
-
new(url.host, url.port)
|
107
|
-
|
108
|
-
http.read_timeout = http_read_timeout
|
109
|
-
http.open_timeout = http_open_timeout
|
110
|
-
|
111
|
-
if secure?
|
112
|
-
http.use_ssl = true
|
113
|
-
|
114
|
-
http.ca_file = Airbrake.configuration.ca_bundle_path
|
115
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
116
|
-
else
|
117
|
-
http.use_ssl = false
|
118
|
-
end
|
119
|
-
|
120
|
-
http
|
121
|
-
rescue => e
|
122
|
-
log :level => :error,
|
123
|
-
:message => "[Airbrake::Sender#setup_http_connection] Failure initializing the HTTP connection.\n" +
|
124
|
-
"Error: #{e.class} - #{e.message}\nBacktrace:\n#{e.backtrace.join("\n\t")}"
|
125
|
-
raise e
|
126
|
-
end
|
127
|
-
end
|
128
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
namespace :airbrake do
|
2
|
-
desc "Notify Airbrake of a new deploy."
|
3
|
-
task :deploy do
|
4
|
-
require 'airbrake_tasks'
|
5
|
-
|
6
|
-
if defined?(Rails.root)
|
7
|
-
initializer_file = Rails.root.join('config', 'initializers','airbrake.rb')
|
8
|
-
|
9
|
-
if initializer_file.exist?
|
10
|
-
load initializer_file
|
11
|
-
else
|
12
|
-
Rake::Task[:environment].invoke
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
AirbrakeTasks.deploy(:rails_env => ENV['TO'],
|
17
|
-
:scm_revision => ENV['REVISION'],
|
18
|
-
:scm_repository => ENV['REPO'],
|
19
|
-
:local_username => ENV['USER'],
|
20
|
-
:api_key => ENV['API_KEY'],
|
21
|
-
:dry_run => ENV['DRY_RUN'])
|
22
|
-
end
|
23
|
-
|
24
|
-
task :log_stdout do
|
25
|
-
require 'logger'
|
26
|
-
RAILS_DEFAULT_LOGGER = Logger.new(STDOUT)
|
27
|
-
end
|
28
|
-
|
29
|
-
namespace :heroku do
|
30
|
-
desc "Install Heroku deploy notifications addon"
|
31
|
-
task :add_deploy_notification => [:environment] do
|
32
|
-
|
33
|
-
def heroku_var(var)
|
34
|
-
`heroku config | grep -E "#{var.upcase}" | awk '{ print $3; }'`.strip
|
35
|
-
end
|
36
|
-
|
37
|
-
heroku_rails_env = heroku_var("rails_env")
|
38
|
-
heroku_api_key = heroku_var("(hoptoad|airbrake)_api_key").split.find {|x| x unless x.blank?} ||
|
39
|
-
Airbrake.configuration.api_key
|
40
|
-
|
41
|
-
command = %Q(heroku addons:add deployhooks:http --url="http://airbrake.io/deploys.txt?deploy[rails_env]=#{heroku_rails_env}&api_key=#{heroku_api_key}")
|
42
|
-
|
43
|
-
puts "\nRunning:\n#{command}\n"
|
44
|
-
puts `#{command}`
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
data/lib/airbrake/tasks.rb
DELETED
@@ -1,83 +0,0 @@
|
|
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 => ['airbrake:log_stdout', :environment] do
|
7
|
-
RAILS_DEFAULT_LOGGER.level = Logger::DEBUG
|
8
|
-
|
9
|
-
require 'action_controller/test_process'
|
10
|
-
|
11
|
-
Dir["app/controllers/application*.rb"].each { |file| require(File.expand_path(file)) }
|
12
|
-
|
13
|
-
class AirbrakeTestingException < RuntimeError; end
|
14
|
-
|
15
|
-
unless Airbrake.configuration.api_key
|
16
|
-
puts "Airbrake needs an API key configured! Check the README to see how to add it."
|
17
|
-
exit
|
18
|
-
end
|
19
|
-
|
20
|
-
Airbrake.configuration.development_environments = []
|
21
|
-
|
22
|
-
catcher = Airbrake::Rails::ActionControllerCatcher
|
23
|
-
in_controller = ApplicationController.included_modules.include?(catcher)
|
24
|
-
in_base = ActionController::Base.included_modules.include?(catcher)
|
25
|
-
if !in_controller || !in_base
|
26
|
-
puts "Rails initialization did not occur"
|
27
|
-
exit
|
28
|
-
end
|
29
|
-
|
30
|
-
puts "Configuration:"
|
31
|
-
Airbrake.configuration.to_hash.each do |key, value|
|
32
|
-
puts sprintf("%25s: %s", key.to_s, value.inspect.slice(0, 55))
|
33
|
-
end
|
34
|
-
|
35
|
-
unless defined?(ApplicationController)
|
36
|
-
puts "No ApplicationController found"
|
37
|
-
exit
|
38
|
-
end
|
39
|
-
|
40
|
-
puts 'Setting up the Controller.'
|
41
|
-
class ApplicationController
|
42
|
-
# This is to bypass any filters that may prevent access to the action.
|
43
|
-
prepend_before_filter :test_airbrake
|
44
|
-
def test_airbrake
|
45
|
-
puts "Raising '#{exception_class.name}' to simulate application failure."
|
46
|
-
raise exception_class.new, 'Testing airbrake via "rake airbrake:test". If you can see this, it works.'
|
47
|
-
end
|
48
|
-
|
49
|
-
def rescue_action(exception)
|
50
|
-
rescue_action_in_public exception
|
51
|
-
end
|
52
|
-
|
53
|
-
# Ensure we actually have an action to go to.
|
54
|
-
def verify; end
|
55
|
-
|
56
|
-
def consider_all_requests_local
|
57
|
-
false
|
58
|
-
end
|
59
|
-
|
60
|
-
def local_request?
|
61
|
-
false
|
62
|
-
end
|
63
|
-
|
64
|
-
def exception_class
|
65
|
-
exception_name = ENV['EXCEPTION'] || "AirbrakeTestingException"
|
66
|
-
exception_name.split("::").inject(Object){|klass, name| klass.const_get(name)}
|
67
|
-
rescue
|
68
|
-
Object.const_set(exception_name.gsub(/:+/, "_"), Class.new(Exception))
|
69
|
-
end
|
70
|
-
|
71
|
-
def logger
|
72
|
-
nil
|
73
|
-
end
|
74
|
-
end
|
75
|
-
class AirbrakeVerificationController < ApplicationController; end
|
76
|
-
|
77
|
-
puts 'Processing request.'
|
78
|
-
request = ActionController::TestRequest.new("REQUEST_URI" => "/airbrake_verification_controller")
|
79
|
-
response = ActionController::TestResponse.new
|
80
|
-
AirbrakeVerificationController.new.process(request, response)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
@@ -1,27 +0,0 @@
|
|
1
|
-
module Airbrake
|
2
|
-
class UserInformer
|
3
|
-
def initialize(app)
|
4
|
-
@app = app
|
5
|
-
end
|
6
|
-
|
7
|
-
def replacement(with)
|
8
|
-
Airbrake.configuration.user_information.gsub(/\{\{\s*error_id\s*\}\}/, with.to_s)
|
9
|
-
end
|
10
|
-
|
11
|
-
def call(env)
|
12
|
-
status, headers, body = @app.call(env)
|
13
|
-
if env['airbrake.error_id'] && Airbrake.configuration.user_information
|
14
|
-
new_body = []
|
15
|
-
replace = replacement(env['airbrake.error_id'])
|
16
|
-
body.each do |chunk|
|
17
|
-
new_body << chunk.gsub("<!-- AIRBRAKE ERROR -->", replace)
|
18
|
-
end
|
19
|
-
body.close if body.respond_to?(:close)
|
20
|
-
headers['Content-Length'] = new_body.sum(&:bytesize).to_s
|
21
|
-
body = new_body
|
22
|
-
end
|
23
|
-
[status, headers, body]
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
data/lib/airbrake_tasks.rb
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
require 'net/http'
|
2
|
-
require 'uri'
|
3
|
-
|
4
|
-
# Capistrano tasks for notifying Airbrake of deploys
|
5
|
-
module AirbrakeTasks
|
6
|
-
|
7
|
-
# Alerts Airbrake of a deploy.
|
8
|
-
#
|
9
|
-
# @param [Hash] opts Data about the deploy that is set to Airbrake
|
10
|
-
#
|
11
|
-
# @option opts [String] :api_key Api key of you Airbrake application
|
12
|
-
# @option opts [String] :rails_env Environment of the deploy (production, staging)
|
13
|
-
# @option opts [String] :scm_revision The given revision/sha that is being deployed
|
14
|
-
# @option opts [String] :scm_repository Address of your repository to help with code lookups
|
15
|
-
# @option opts [String] :local_username Who is deploying
|
16
|
-
def self.deploy(opts = {})
|
17
|
-
api_key = opts.delete(:api_key) || Airbrake.configuration.api_key
|
18
|
-
if api_key.blank?
|
19
|
-
puts "I don't seem to be configured with an API key. Please check your configuration."
|
20
|
-
return false
|
21
|
-
end
|
22
|
-
|
23
|
-
if opts[:rails_env].blank?
|
24
|
-
puts "I don't know to which Rails environment you are deploying (use the TO=production option)."
|
25
|
-
return false
|
26
|
-
end
|
27
|
-
|
28
|
-
dry_run = opts.delete(:dry_run)
|
29
|
-
params = {'api_key' => api_key}
|
30
|
-
opts.each {|k,v| params["deploy[#{k}]"] = v }
|
31
|
-
|
32
|
-
host = Airbrake.configuration.host || 'api.airbrake.io'
|
33
|
-
port = Airbrake.configuration.port
|
34
|
-
|
35
|
-
proxy = Net::HTTP.Proxy(Airbrake.configuration.proxy_host,
|
36
|
-
Airbrake.configuration.proxy_port,
|
37
|
-
Airbrake.configuration.proxy_user,
|
38
|
-
Airbrake.configuration.proxy_pass)
|
39
|
-
http = proxy.new(host, port)
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
# Handle Security
|
44
|
-
if Airbrake.configuration.secure?
|
45
|
-
http.use_ssl = true
|
46
|
-
http.ca_file = Airbrake.configuration.ca_bundle_path
|
47
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
48
|
-
end
|
49
|
-
|
50
|
-
post = Net::HTTP::Post.new("/deploys.txt")
|
51
|
-
post.set_form_data(params)
|
52
|
-
|
53
|
-
if dry_run
|
54
|
-
puts http.inspect, params.inspect
|
55
|
-
return true
|
56
|
-
else
|
57
|
-
response = http.request(post)
|
58
|
-
|
59
|
-
puts response.body
|
60
|
-
return Net::HTTPSuccess === response
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
@@ -1,100 +0,0 @@
|
|
1
|
-
require 'rails/generators'
|
2
|
-
|
3
|
-
class AirbrakeGenerator < Rails::Generators::Base
|
4
|
-
|
5
|
-
class_option :api_key, :aliases => "-k", :type => :string, :desc => "Your Airbrake API key"
|
6
|
-
class_option :heroku, :type => :boolean, :desc => "Use the Heroku addon to provide your Airbrake API key"
|
7
|
-
class_option :app, :aliases => "-a", :type => :string, :desc => "Your Heroku app name (only required if deploying to >1 Heroku app)"
|
8
|
-
|
9
|
-
def self.source_root
|
10
|
-
@_airbrake_source_root ||= File.expand_path("../../../../../generators/airbrake/templates", __FILE__)
|
11
|
-
end
|
12
|
-
|
13
|
-
def install
|
14
|
-
ensure_api_key_was_configured
|
15
|
-
ensure_plugin_is_not_present
|
16
|
-
append_capistrano_hook
|
17
|
-
generate_initializer unless api_key_configured?
|
18
|
-
determine_api_key if heroku?
|
19
|
-
test_airbrake
|
20
|
-
end
|
21
|
-
|
22
|
-
private
|
23
|
-
|
24
|
-
def ensure_api_key_was_configured
|
25
|
-
if !options[:api_key] && !options[:heroku] && !api_key_configured?
|
26
|
-
puts "Must pass --api-key or --heroku or create config/initializers/airbrake.rb"
|
27
|
-
exit
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def ensure_plugin_is_not_present
|
32
|
-
if plugin_is_present?
|
33
|
-
puts "You must first remove the airbrake plugin. Please run: script/plugin remove airbrake"
|
34
|
-
exit
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def append_capistrano_hook
|
39
|
-
if File.exists?('config/deploy.rb') && File.exists?('Capfile')
|
40
|
-
append_file('config/deploy.rb', <<-HOOK)
|
41
|
-
|
42
|
-
require './config/boot'
|
43
|
-
require 'airbrake/capistrano'
|
44
|
-
HOOK
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def api_key_expression
|
49
|
-
s = if options[:api_key]
|
50
|
-
"'#{options[:api_key]}'"
|
51
|
-
elsif options[:heroku]
|
52
|
-
"ENV['HOPTOAD_API_KEY']"
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def generate_initializer
|
57
|
-
template 'initializer.rb', 'config/initializers/airbrake.rb'
|
58
|
-
end
|
59
|
-
|
60
|
-
def determine_api_key
|
61
|
-
puts "Attempting to determine your API Key from Heroku..."
|
62
|
-
ENV['HOPTOAD_API_KEY'] = heroku_api_key
|
63
|
-
if ENV['HOPTOAD_API_KEY'].blank?
|
64
|
-
puts "... Failed."
|
65
|
-
puts "WARNING: We were unable to detect the Airbrake API Key from your Heroku environment."
|
66
|
-
puts "Your Heroku application environment may not be configured correctly."
|
67
|
-
exit 1
|
68
|
-
else
|
69
|
-
puts "... Done."
|
70
|
-
puts "Heroku's Airbrake API Key is '#{ENV['HOPTOAD_API_KEY']}'"
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
def heroku_var(var,app_name = nil)
|
75
|
-
app = app_name ? "--app #{app_name}" : ''
|
76
|
-
`heroku config #{app} | grep -E "#{var.upcase}" | awk '{ print $3; }'`.strip
|
77
|
-
end
|
78
|
-
|
79
|
-
def heroku_api_key
|
80
|
-
heroku_var("(hoptoad|airbrake)_api_key",options[:app]).split.find {|x| x unless x.blank?}
|
81
|
-
end
|
82
|
-
|
83
|
-
def heroku?
|
84
|
-
options[:heroku] ||
|
85
|
-
system("grep HOPTOAD_API_KEY config/initializers/airbrake.rb") ||
|
86
|
-
system("grep HOPTOAD_API_KEY config/environment.rb")
|
87
|
-
end
|
88
|
-
|
89
|
-
def api_key_configured?
|
90
|
-
File.exists?('config/initializers/airbrake.rb')
|
91
|
-
end
|
92
|
-
|
93
|
-
def test_airbrake
|
94
|
-
puts run("rake airbrake:test --trace")
|
95
|
-
end
|
96
|
-
|
97
|
-
def plugin_is_present?
|
98
|
-
File.exists?('vendor/plugins/airbrake')
|
99
|
-
end
|
100
|
-
end
|