airbrake 4.3.8 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. checksums.yaml +4 -4
  2. data/lib/airbrake/capistrano/tasks.rb +64 -0
  3. data/lib/airbrake/delayed_job/plugin.rb +48 -0
  4. data/lib/airbrake/rack/middleware.rb +45 -0
  5. data/lib/airbrake/rack/notice_builder.rb +80 -0
  6. data/lib/airbrake/rack/user.rb +51 -0
  7. data/lib/airbrake/rails/action_controller.rb +35 -0
  8. data/lib/airbrake/rails/active_job.rb +23 -0
  9. data/lib/airbrake/rails/active_record.rb +40 -0
  10. data/lib/airbrake/rails/railtie.rb +61 -0
  11. data/lib/airbrake/rake/task_ext.rb +61 -0
  12. data/lib/airbrake/rake/tasks.rb +93 -0
  13. data/lib/airbrake/resque/failure.rb +19 -0
  14. data/lib/airbrake/sidekiq/error_handler.rb +35 -0
  15. data/lib/airbrake/version.rb +4 -1
  16. data/lib/airbrake.rb +16 -185
  17. data/lib/generators/airbrake_generator.rb +25 -0
  18. data/lib/generators/airbrake_initializer.rb.erb +55 -0
  19. data/spec/airbrake_spec.rb +0 -0
  20. data/spec/apps/rack/dummy_app.rb +17 -0
  21. data/spec/apps/rails/dummy_app.rb +150 -0
  22. data/spec/apps/rails/dummy_task.rake +20 -0
  23. data/spec/apps/rails/logs/32.log +13358 -0
  24. data/spec/apps/rails/logs/40.log +6854 -0
  25. data/spec/apps/rails/logs/41.log +3170 -0
  26. data/spec/apps/rails/logs/42.log +23919 -0
  27. data/spec/apps/rails/logs/50.log +10976 -0
  28. data/spec/apps/sinatra/dummy_app.rb +12 -0
  29. data/spec/integration/rack/rack_spec.rb +17 -0
  30. data/spec/integration/rails/rails_spec.rb +135 -0
  31. data/spec/integration/rails/rake_spec.rb +160 -0
  32. data/spec/integration/shared_examples/rack_examples.rb +106 -0
  33. data/spec/integration/sinatra/sinatra_spec.rb +15 -0
  34. data/spec/spec_helper.rb +127 -0
  35. data/spec/unit/rack/middleware_spec.rb +80 -0
  36. data/spec/unit/rack/notice_builder_spec.rb +35 -0
  37. data/spec/unit/rack/user_spec.rb +78 -0
  38. data/spec/unit/rake/tasks_spec.rb +40 -0
  39. data/spec/unit/sidekiq/error_handler_spec.rb +29 -0
  40. metadata +108 -323
  41. data/CHANGELOG +0 -1716
  42. data/Gemfile +0 -3
  43. data/Guardfile +0 -6
  44. data/INSTALL +0 -20
  45. data/LICENSE +0 -61
  46. data/README.md +0 -148
  47. data/README_FOR_HEROKU_ADDON.md +0 -102
  48. data/Rakefile +0 -179
  49. data/TESTED_AGAINST +0 -7
  50. data/airbrake.gemspec +0 -41
  51. data/bin/airbrake +0 -12
  52. data/features/metal.feature +0 -34
  53. data/features/rack.feature +0 -60
  54. data/features/rails.feature +0 -324
  55. data/features/rake.feature +0 -33
  56. data/features/sinatra.feature +0 -126
  57. data/features/step_definitions/file_steps.rb +0 -14
  58. data/features/step_definitions/rack_steps.rb +0 -27
  59. data/features/step_definitions/rails_application_steps.rb +0 -267
  60. data/features/step_definitions/rake_steps.rb +0 -22
  61. data/features/support/airbrake_shim.rb.template +0 -11
  62. data/features/support/aruba.rb +0 -5
  63. data/features/support/env.rb +0 -39
  64. data/features/support/matchers.rb +0 -35
  65. data/features/support/rails.rb +0 -156
  66. data/features/support/rake/Rakefile +0 -77
  67. data/features/user_informer.feature +0 -57
  68. data/generators/airbrake/airbrake_generator.rb +0 -94
  69. data/generators/airbrake/lib/insert_commands.rb +0 -34
  70. data/generators/airbrake/lib/rake_commands.rb +0 -24
  71. data/generators/airbrake/templates/airbrake_tasks.rake +0 -25
  72. data/generators/airbrake/templates/capistrano_hook.rb +0 -6
  73. data/generators/airbrake/templates/initializer.rb +0 -4
  74. data/install.rb +0 -1
  75. data/lib/airbrake/backtrace.rb +0 -103
  76. data/lib/airbrake/capistrano.rb +0 -103
  77. data/lib/airbrake/capistrano3.rb +0 -3
  78. data/lib/airbrake/cli/client.rb +0 -76
  79. data/lib/airbrake/cli/options.rb +0 -45
  80. data/lib/airbrake/cli/printer.rb +0 -33
  81. data/lib/airbrake/cli/project.rb +0 -17
  82. data/lib/airbrake/cli/project_factory.rb +0 -33
  83. data/lib/airbrake/cli/runner.rb +0 -49
  84. data/lib/airbrake/cli/validator.rb +0 -8
  85. data/lib/airbrake/configuration.rb +0 -366
  86. data/lib/airbrake/jobs/send_job.rb +0 -7
  87. data/lib/airbrake/notice.rb +0 -411
  88. data/lib/airbrake/rack.rb +0 -64
  89. data/lib/airbrake/rails/action_controller_catcher.rb +0 -32
  90. data/lib/airbrake/rails/controller_methods.rb +0 -146
  91. data/lib/airbrake/rails/error_lookup.rb +0 -35
  92. data/lib/airbrake/rails/middleware.rb +0 -63
  93. data/lib/airbrake/rails.rb +0 -45
  94. data/lib/airbrake/rails3_tasks.rb +0 -126
  95. data/lib/airbrake/railtie.rb +0 -46
  96. data/lib/airbrake/rake_handler.rb +0 -75
  97. data/lib/airbrake/response.rb +0 -29
  98. data/lib/airbrake/sender.rb +0 -213
  99. data/lib/airbrake/shared_tasks.rb +0 -59
  100. data/lib/airbrake/sidekiq.rb +0 -8
  101. data/lib/airbrake/sinatra.rb +0 -40
  102. data/lib/airbrake/tasks/airbrake.cap +0 -28
  103. data/lib/airbrake/tasks.rb +0 -81
  104. data/lib/airbrake/user_informer.rb +0 -36
  105. data/lib/airbrake/utils/params_cleaner.rb +0 -141
  106. data/lib/airbrake/utils/rack_filters.rb +0 -45
  107. data/lib/airbrake_tasks.rb +0 -62
  108. data/lib/rails/generators/airbrake/airbrake_generator.rb +0 -155
  109. data/lib/templates/rescue.erb +0 -91
  110. data/rails/init.rb +0 -1
  111. data/resources/README.md +0 -34
  112. data/resources/airbrake_2_4.xsd +0 -89
  113. data/resources/airbrake_3_0.json +0 -52
  114. data/resources/ca-bundle.crt +0 -3376
  115. data/script/integration_test.rb +0 -35
  116. data/test/airbrake_tasks_test.rb +0 -161
  117. data/test/backtrace_test.rb +0 -215
  118. data/test/capistrano_test.rb +0 -44
  119. data/test/configuration_test.rb +0 -303
  120. data/test/controller_methods_test.rb +0 -230
  121. data/test/helper.rb +0 -233
  122. data/test/integration/catcher_test.rb +0 -371
  123. data/test/integration.rb +0 -13
  124. data/test/logger_test.rb +0 -79
  125. data/test/notice_test.rb +0 -494
  126. data/test/notifier_test.rb +0 -288
  127. data/test/params_cleaner_test.rb +0 -204
  128. data/test/rack_test.rb +0 -62
  129. data/test/rails_initializer_test.rb +0 -36
  130. data/test/recursion_test.rb +0 -10
  131. data/test/response_test.rb +0 -18
  132. data/test/sender_test.rb +0 -335
  133. data/test/support/response_shim.xml +0 -4
  134. data/test/user_informer_test.rb +0 -29
@@ -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,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,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
-
@@ -1,46 +0,0 @@
1
- require 'airbrake'
2
- require 'rails'
3
-
4
- require 'airbrake/rails/middleware'
5
-
6
- module Airbrake
7
- class Railtie < ::Rails::Railtie
8
- rake_tasks do
9
- require 'airbrake/rake_handler'
10
- require 'airbrake/rails3_tasks'
11
- end
12
-
13
- initializer "airbrake.middleware" do |app|
14
-
15
- middleware = if defined?(ActionDispatch::DebugExceptions)
16
- # Rails >= 3.2.0
17
- "ActionDispatch::DebugExceptions"
18
- else
19
- # Rails < 3.2.0
20
- "ActionDispatch::ShowExceptions"
21
- end
22
-
23
- app.config.middleware.insert_after middleware,
24
- "Airbrake::Rails::Middleware"
25
-
26
- app.config.middleware.insert 0, "Airbrake::UserInformer"
27
- end
28
-
29
- config.after_initialize do
30
- Airbrake.configure(true) do |config|
31
- config.logger ||= config.async? ? ::Logger.new(STDERR) : ::Rails.logger
32
- config.environment_name ||= ::Rails.env
33
- config.project_root ||= ::Rails.root
34
- config.framework = "Rails: #{::Rails::VERSION::STRING}"
35
- end
36
-
37
- ActiveSupport.on_load(:action_controller) do
38
- # Lazily load action_controller methods
39
- #
40
- require 'airbrake/rails/controller_methods'
41
-
42
- include Airbrake::Rails::ControllerMethods
43
- end
44
- end
45
- end
46
- end
@@ -1,75 +0,0 @@
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(exception)
12
- if Airbrake.sender && Airbrake.configuration &&
13
- (Airbrake.configuration.rescue_rake_exceptions ||
14
- (Airbrake.configuration.rescue_rake_exceptions===nil && !self.tty_output?))
15
-
16
- Airbrake.notify_or_ignore(exception,
17
- :component => 'rake',
18
- :action => reconstruct_command_line,
19
- :cgi_data => environment_info,
20
- :ignore => Airbrake.configuration.ignore_rake)
21
- end
22
-
23
- display_error_message_without_airbrake(exception)
24
- end
25
-
26
- def reconstruct_command_line
27
- ARGV.join(' ')
28
- end
29
-
30
- def environment_info
31
- ENV.reject do |k|
32
- Airbrake.configuration.rake_environment_filters.include? k
33
- end
34
- end
35
-
36
- # This module brings Rake 0.8.7 error handling to 0.9.0 standards
37
- module Rake087Methods
38
- # Method taken from Rake 0.9.0 source
39
- #
40
- # Provide standard exception handling for the given block.
41
- def standard_exception_handling
42
- begin
43
- yield
44
- rescue SystemExit => ex
45
- # Exit silently with current status
46
- raise
47
- rescue OptionParser::InvalidOption => ex
48
- $stderr.puts ex.message
49
- exit(false)
50
- rescue Exception => ex
51
- # Exit with error message
52
- display_error_message(ex)
53
- exit(false)
54
- end
55
- end
56
-
57
- # Method extracted from Rake 0.8.7 source
58
- def display_error_message(ex)
59
- $stderr.puts "#{name} aborted!"
60
- $stderr.puts ex.message
61
- if options.trace
62
- $stderr.puts ex.backtrace.join("\n")
63
- else
64
- $stderr.puts ex.backtrace.find {|str| str =~ /#{@rakefile}/ } || ""
65
- $stderr.puts "(See full trace by running task with --trace)"
66
- end
67
- end
68
- end
69
- end
70
-
71
- Rake.application.instance_eval do
72
- class << self
73
- include Airbrake::RakeHandler
74
- end
75
- end
@@ -1,29 +0,0 @@
1
- module Airbrake
2
- class Response
3
- def self.pretty_format(xml_body)
4
- new(xml_body)
5
- rescue
6
- xml_body
7
- end
8
-
9
- def to_s
10
- output = "\n"
11
- output = "UUID: #{@id}"
12
- output << "\n"
13
- output << "URL: #{@url}"
14
- output
15
- end
16
-
17
- private
18
-
19
- def initialize(xml_body)
20
- @xml_body = xml_body
21
- @url = parse_tag("url")
22
- @id = parse_tag("id")
23
- end
24
-
25
- def parse_tag(name)
26
- @xml_body.match(%r{<#{name}[^>]*>(.*?)</#{name}>})[1]
27
- end
28
- end
29
- end
@@ -1,213 +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
- HEADERS = {
7
- :xml => {
8
- 'Content-type' => 'text/xml',
9
- 'Accept' => 'text/xml, application/xml'
10
- },:json => {
11
- 'Content-Type' => 'application/json',
12
- 'Accept' => 'application/json'
13
- }}
14
-
15
- JSON_API_URI = '/api/v3/projects'.freeze
16
- HTTP_ERRORS = [Timeout::Error,
17
- Errno::EINVAL,
18
- Errno::ECONNRESET,
19
- EOFError,
20
- Net::HTTPBadResponse,
21
- Net::HTTPHeaderSyntaxError,
22
- Net::ProtocolError,
23
- Errno::ECONNREFUSED,
24
- OpenSSL::SSL::SSLError].freeze
25
-
26
- def initialize(options = {})
27
- [ :proxy_host,
28
- :proxy_port,
29
- :proxy_user,
30
- :proxy_pass,
31
- :protocol,
32
- :host,
33
- :port,
34
- :secure,
35
- :use_system_ssl_cert_chain,
36
- :http_open_timeout,
37
- :http_read_timeout,
38
- :project_id,
39
- :api_key
40
- ].each do |option|
41
- instance_variable_set("@#{option}", options[option])
42
- end
43
- end
44
-
45
-
46
- # Sends the notice data off to Airbrake for processing.
47
- #
48
- # @param [Notice or String] notice The notice to be sent off
49
- def send_to_airbrake(notice)
50
- data = prepare_notice(notice)
51
- http = setup_http_connection
52
-
53
- response = begin
54
- http.post(request_uri,
55
- data,
56
- headers)
57
- rescue *HTTP_ERRORS => e
58
- log :level => :error,
59
- :message => "Unable to contact the Airbrake server. HTTP Error=#{e}"
60
- nil
61
- end
62
-
63
- case response
64
- when Net::HTTPSuccess then
65
- log :level => :info,
66
- :message => "Success: #{response.class}",
67
- :response => response
68
- else
69
- log :level => :error,
70
- :message => "Failure: #{response.class}",
71
- :response => response,
72
- :notice => notice
73
- end
74
-
75
- if response && response.respond_to?(:body)
76
- error_id = response.body.match(%r{<id[^>]*>(.*?)</id>})
77
- error_id[1] if error_id
78
- end
79
- rescue => e
80
- log :level => :error,
81
- :message => "[Airbrake::Sender#send_to_airbrake] Cannot send notification. Error: #{e.class}" +
82
- " - #{e.message}\nBacktrace:\n#{e.backtrace.join("\n\t")}"
83
-
84
- nil
85
- end
86
-
87
- attr_reader :proxy_host,
88
- :proxy_port,
89
- :proxy_user,
90
- :proxy_pass,
91
- :protocol,
92
- :host,
93
- :port,
94
- :secure,
95
- :use_system_ssl_cert_chain,
96
- :http_open_timeout,
97
- :http_read_timeout,
98
- :project_id,
99
- :api_key
100
-
101
- alias_method :secure?, :secure
102
- alias_method :use_system_ssl_cert_chain?, :use_system_ssl_cert_chain
103
-
104
- private
105
-
106
- def prepare_notice(notice)
107
- if json_api_enabled?
108
- begin
109
- JSON.parse(notice)
110
- notice
111
- rescue
112
- notice.to_json
113
- end
114
- else
115
- notice.respond_to?(:to_xml) ? notice.to_xml : notice
116
- end
117
- end
118
-
119
- def api_url
120
- if json_api_enabled?
121
- "#{JSON_API_URI}/#{project_id}/notices?key=#{api_key}"
122
- else
123
- NOTICES_URI
124
- end
125
- end
126
-
127
- def headers
128
- if json_api_enabled?
129
- HEADERS[:json]
130
- else
131
- HEADERS[:xml]
132
- end
133
- end
134
-
135
- def url
136
- URI.parse("#{protocol}://#{host}:#{port}").merge(api_url)
137
- end
138
-
139
- def log(opts = {})
140
- (opts[:logger] || logger).send(opts[:level], LOG_PREFIX + opts[:message])
141
- Airbrake.report_environment_info
142
- Airbrake.report_response_body(opts[:response].body) if opts[:response] && opts[:response].respond_to?(:body)
143
- Airbrake.report_notice(opts[:notice]) if opts[:notice]
144
- end
145
-
146
- def logger
147
- Airbrake.logger
148
- end
149
-
150
- def setup_http_connection
151
- http =
152
- Net::HTTP::Proxy(proxy_host, proxy_port, proxy_user, proxy_pass).
153
- new(url.host, url.port)
154
-
155
- http.read_timeout = http_read_timeout
156
- http.open_timeout = http_open_timeout
157
-
158
- if secure?
159
- http.use_ssl = true
160
-
161
- http.ca_file = Airbrake.configuration.ca_bundle_path
162
- http.verify_mode = OpenSSL::SSL::VERIFY_PEER
163
- else
164
- http.use_ssl = false
165
- end
166
-
167
- http
168
- rescue => e
169
- log :level => :error,
170
- :message => "[Airbrake::Sender#setup_http_connection] Failure initializing the HTTP connection.\n" +
171
- "Error: #{e.class} - #{e.message}\nBacktrace:\n#{e.backtrace.join("\n\t")}"
172
- raise e
173
- end
174
-
175
- def json_api_enabled?
176
- !!(host =~ /collect.airbrake.io/) &&
177
- project_id =~ /\S/
178
- end
179
-
180
- # Use request_uri[0] to keep the query since it contains the API_KEY.
181
- #
182
- # [0] http://ruby-doc.org/stdlib-2.2.2/libdoc/uri/rdoc/URI/HTTP.html#method-i-request_uri
183
- def request_uri
184
- url.respond_to?(:request_uri) ? url.request_uri : url
185
- end
186
- end
187
-
188
- class CollectingSender < Sender
189
- # Used when test mode is enabled, to store the last XML notice locally
190
-
191
- attr_writer :last_notice_path
192
-
193
- def last_notice
194
- File.read last_notice_path
195
- end
196
-
197
- def last_notice_path
198
- File.expand_path(File.join("..", "..", "..", "resources", "notice.xml"), __FILE__)
199
- end
200
-
201
- def send_to_airbrake(notice)
202
- data = prepare_notice(notice)
203
-
204
- notices_file = File.open(last_notice_path, "w") do |file|
205
- file.puts data
206
- end
207
-
208
- super(notice)
209
- ensure
210
- notices_file.close if notices_file
211
- end
212
- end
213
- end
@@ -1,59 +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
- :dry_run => ENV['DRY_RUN'])
21
- end
22
-
23
- task :log_stdout do
24
- require 'logger'
25
- RAILS_DEFAULT_LOGGER = Logger.new(STDOUT)
26
- end
27
-
28
- namespace :heroku do
29
- desc "Install Heroku deploy notifications addon"
30
- task :add_deploy_notification => [:environment] do
31
-
32
- def get_heroku_vars
33
- config = `heroku config --shell`
34
- array_of_vars = config.split.map do |var|
35
- var.partition("=").tap {|part| part.delete_at(1)}
36
- end.flatten
37
- @heroku_vars = Hash[*array_of_vars]
38
- end
39
-
40
- get_heroku_vars
41
-
42
- heroku_rails_env = @heroku_vars["RAILS_ENV"] || ENV["RAILS_ENV"] || "production"
43
- heroku_api_key = @heroku_vars["AIRBRAKE_API_KEY"] || Airbrake.configuration.api_key || ENV["AIRBRAKE_API_KEY"]
44
- heroku_app = ENV["HEROKU_APP"]
45
- repo = `git config --get remote.origin.url` || ENV["REPO"]
46
-
47
- command = %Q(heroku addons:add deployhooks:http --url="http://airbrake.io/deploys.txt?api_key=#{heroku_api_key})
48
- command << "&deploy[local_username]={{user}}"
49
- command << "&deploy[scm_revision]={{head_long}}"
50
- command << "&deploy[rails_env]=#{heroku_rails_env}" if heroku_rails_env
51
- command << "&deploy[scm_repository]=#{repo}" if repo
52
- command << '"'
53
- command << " --app=#{heroku_app}" if heroku_app
54
-
55
- puts "\nRunning:\n#{command}\n"
56
- puts `#{command}`
57
- end
58
- end
59
- end
@@ -1,8 +0,0 @@
1
- gem 'sidekiq', '>= 3.0'
2
- require 'sidekiq'
3
-
4
- Sidekiq.configure_server do |config|
5
- config.error_handlers << lambda do |exception, context|
6
- Airbrake.notify_or_ignore(exception, :parameters => context)
7
- end
8
- end