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.
Files changed (134) hide show
  1. checksums.yaml +4 -4
  2. data/lib/airbrake.rb +16 -185
  3. data/lib/airbrake/capistrano/tasks.rb +64 -0
  4. data/lib/airbrake/delayed_job/plugin.rb +48 -0
  5. data/lib/airbrake/rack/middleware.rb +45 -0
  6. data/lib/airbrake/rack/notice_builder.rb +80 -0
  7. data/lib/airbrake/rack/user.rb +51 -0
  8. data/lib/airbrake/rails/action_controller.rb +35 -0
  9. data/lib/airbrake/rails/active_job.rb +23 -0
  10. data/lib/airbrake/rails/active_record.rb +40 -0
  11. data/lib/airbrake/rails/railtie.rb +61 -0
  12. data/lib/airbrake/rake/task_ext.rb +61 -0
  13. data/lib/airbrake/rake/tasks.rb +93 -0
  14. data/lib/airbrake/resque/failure.rb +19 -0
  15. data/lib/airbrake/sidekiq/error_handler.rb +35 -0
  16. data/lib/airbrake/version.rb +4 -1
  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 +110 -325
  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.rb +0 -45
  90. data/lib/airbrake/rails/action_controller_catcher.rb +0 -32
  91. data/lib/airbrake/rails/controller_methods.rb +0 -146
  92. data/lib/airbrake/rails/error_lookup.rb +0 -35
  93. data/lib/airbrake/rails/middleware.rb +0 -63
  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.rb +0 -81
  103. data/lib/airbrake/tasks/airbrake.cap +0 -28
  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.rb +0 -13
  123. data/test/integration/catcher_test.rb +0 -371
  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,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
@@ -1,40 +0,0 @@
1
- module Airbrake
2
- # Middleware for Sinatra applications. Any errors raised by the upstream
3
- # application will be delivered to Airbrake and re-raised.
4
-
5
- # Synopsis:
6
-
7
- # require 'sinatra'
8
- # require 'airbrake'
9
-
10
- # Airbrake.configure do |config|
11
- # config.api_key = 'my api key'
12
- # end
13
-
14
- # use Airbrake::Sinatra
15
-
16
- # get '/' do
17
- # raise "Sinatra has left the building"
18
- # end
19
- #
20
- # Use a standard Airbrake.configure call to configure your api key.
21
- class Sinatra < Rack
22
-
23
- def initialize(app)
24
- super
25
- Airbrake.configuration.environment_name ||= environment_name(app)
26
- Airbrake.configuration.framework = "Sinatra: #{::Sinatra::VERSION}"
27
- end
28
-
29
- def framework_exception(env)
30
- env['sinatra.error']
31
- end
32
-
33
- def environment_name(app)
34
- "#{app.settings.environment}"
35
- rescue
36
- ENV["RACK_ENV"] || warn("[Airbrake] Couldn't determine environment name automatically. "\
37
- "Please set your environment name manually by setting 'config.environment_name='.")
38
- end
39
- end
40
- end