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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a478d42f9ddbdf9ecb24f4ae1ba6fef0050ad83b
|
4
|
+
data.tar.gz: 567e1a0b5fdea978842f8ba8940abc0efe67783a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e02cf763f9b0585ef6eb87cef04b06365e25bd2d0ba56b703e72a79226bad3535db0fb39d5a92ce16d5e68416228b98cab94b78eb32f6ca60c6d1c96232e696
|
7
|
+
data.tar.gz: d653d8f1e75a54392e5a704d78232ce6f198cb5b8433df6183cf405a2474dc0eb634382d6db1f964ea63050ea7a510cb67e25931e2bc5a31128db07169338ecb
|
data/lib/airbrake.rb
CHANGED
@@ -1,191 +1,22 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
rescue LoadError
|
4
|
-
end
|
5
|
-
|
6
|
-
begin
|
7
|
-
require "sucker_punch"
|
8
|
-
rescue LoadError
|
9
|
-
end
|
1
|
+
# For 'Socket.gethostname' only.
|
2
|
+
require 'socket'
|
10
3
|
|
11
|
-
|
12
|
-
|
13
|
-
require '
|
14
|
-
require 'logger'
|
4
|
+
# Core library that sends notices.
|
5
|
+
# See: https://github.com/airbrake/airbrake-ruby
|
6
|
+
require 'airbrake-ruby'
|
15
7
|
|
16
8
|
require 'airbrake/version'
|
17
|
-
require 'airbrake/jobs/send_job'
|
18
|
-
require 'airbrake/utils/rack_filters'
|
19
|
-
require 'airbrake/utils/params_cleaner'
|
20
|
-
require 'airbrake/configuration'
|
21
|
-
require 'airbrake/notice'
|
22
|
-
require 'airbrake/sender'
|
23
|
-
require 'airbrake/response'
|
24
|
-
require 'airbrake/backtrace'
|
25
|
-
require 'airbrake/rack'
|
26
|
-
require 'airbrake/sinatra'
|
27
|
-
require 'airbrake/user_informer'
|
28
|
-
|
29
|
-
begin
|
30
|
-
require 'airbrake/sidekiq'
|
31
|
-
rescue LoadError
|
32
|
-
end
|
33
|
-
|
34
|
-
require 'airbrake/railtie' if defined?(Rails::Railtie)
|
35
|
-
|
36
|
-
module Airbrake
|
37
|
-
API_VERSION = "2.4"
|
38
|
-
LOG_PREFIX = "** [Airbrake] "
|
39
|
-
|
40
|
-
class << self
|
41
|
-
# The sender object is responsible for delivering formatted data to the Airbrake server.
|
42
|
-
# Must respond to #send_to_airbrake. See Airbrake::Sender.
|
43
|
-
attr_accessor :sender
|
44
|
-
|
45
|
-
# A Airbrake configuration object. Must act like a hash and return sensible
|
46
|
-
# values for all Airbrake configuration options. See Airbrake::Configuration.
|
47
|
-
attr_writer :configuration
|
48
|
-
|
49
|
-
# Tell the log that the Notifier is good to go
|
50
|
-
def report_ready
|
51
|
-
write_verbose_log("Notifier #{VERSION} ready to catch errors")
|
52
|
-
end
|
53
|
-
|
54
|
-
# Prints out the environment info to the log for debugging help
|
55
|
-
def report_environment_info
|
56
|
-
write_verbose_log("Environment Info: #{environment_info}")
|
57
|
-
end
|
58
|
-
|
59
|
-
# Prints out the response body from Airbrake for debugging help
|
60
|
-
def report_response_body(response)
|
61
|
-
write_verbose_log("Response from Airbrake: \n#{Response.pretty_format(response)}")
|
62
|
-
end
|
63
|
-
|
64
|
-
# Prints out the details about the notice that wasn't sent to server
|
65
|
-
def report_notice(notice)
|
66
|
-
write_verbose_log("Notice details: \n#{notice}")
|
67
|
-
end
|
68
|
-
|
69
|
-
def report_notice_not_sent_for_configuration
|
70
|
-
write_verbose_log("Notice was not sent due to configuration: \
|
71
|
-
\n Environment Monitored? #{configuration.public?} \
|
72
|
-
\n API key set? #{configuration.configured?}")
|
73
|
-
end
|
74
|
-
|
75
|
-
# Returns the Ruby version, Rails version, and current Rails environment
|
76
|
-
def environment_info
|
77
|
-
info = "[Ruby: #{RUBY_VERSION}]"
|
78
|
-
info << " [#{configuration.framework}]" if configuration.framework
|
79
|
-
info << " [Env: #{configuration.environment_name}]" if configuration.environment_name
|
80
|
-
info
|
81
|
-
end
|
82
9
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
10
|
+
# Automatically load needed files for the environment the library is running in.
|
11
|
+
if defined?(Rack)
|
12
|
+
require 'airbrake/rack/user'
|
13
|
+
require 'airbrake/rack/notice_builder'
|
14
|
+
require 'airbrake/rack/middleware'
|
87
15
|
|
88
|
-
|
89
|
-
def logger
|
90
|
-
self.configuration.logger ||
|
91
|
-
Logger.new(nil)
|
92
|
-
end
|
93
|
-
|
94
|
-
# Call this method to modify defaults in your initializers.
|
95
|
-
#
|
96
|
-
# @example
|
97
|
-
# Airbrake.configure do |config|
|
98
|
-
# config.api_key = '1234567890abcdef'
|
99
|
-
# config.secure = false
|
100
|
-
# end
|
101
|
-
def configure(silent = false)
|
102
|
-
yield(configuration)
|
103
|
-
self.sender = if configuration.test_mode?
|
104
|
-
CollectingSender.new(configuration)
|
105
|
-
else
|
106
|
-
Sender.new(configuration)
|
107
|
-
end
|
108
|
-
|
109
|
-
report_ready unless silent
|
110
|
-
self.sender
|
111
|
-
end
|
112
|
-
|
113
|
-
# The configuration object.
|
114
|
-
# @see Airbrake.configure
|
115
|
-
def configuration
|
116
|
-
@configuration ||= Configuration.new
|
117
|
-
end
|
118
|
-
|
119
|
-
# Sends an exception manually using this method, even when you are not in a controller.
|
120
|
-
#
|
121
|
-
# @param [Exception] exception The exception you want to notify Airbrake about.
|
122
|
-
# @param [Hash] opts Data that will be sent to Airbrake.
|
123
|
-
#
|
124
|
-
# @option opts [String] :api_key The API key for this project. The API key is a unique identifier that Airbrake uses for identification.
|
125
|
-
# @option opts [String] :error_message The error returned by the exception (or the message you want to log).
|
126
|
-
# @option opts [String] :backtrace A backtrace, usually obtained with +caller+.
|
127
|
-
# @option opts [String] :rack_env The Rack environment.
|
128
|
-
# @option opts [String] :session The contents of the user's session.
|
129
|
-
# @option opts [String] :environment_name The application environment name.
|
130
|
-
# @option opts [String] :parameters Additional parameters.
|
131
|
-
def notify(exception, opts = {})
|
132
|
-
send_notice(build_notice_for(exception, opts))
|
133
|
-
end
|
134
|
-
|
135
|
-
# Sends the notice unless it is one of the default ignored exceptions
|
136
|
-
# @see Airbrake.notify
|
137
|
-
def notify_or_ignore(exception, opts = {})
|
138
|
-
notice = build_notice_for(exception, opts)
|
139
|
-
send_notice(notice) unless notice.ignore?
|
140
|
-
end
|
141
|
-
|
142
|
-
def build_lookup_hash_for(exception, options = {})
|
143
|
-
notice = build_notice_for(exception, options)
|
144
|
-
|
145
|
-
result = {}
|
146
|
-
result[:action] = notice.action rescue nil
|
147
|
-
result[:component] = notice.component rescue nil
|
148
|
-
result[:error_class] = notice.error_class if notice.error_class
|
149
|
-
result[:environment_name] = 'production'
|
150
|
-
|
151
|
-
unless notice.backtrace.lines.empty?
|
152
|
-
result[:file] = notice.backtrace.lines.first.file
|
153
|
-
result[:line_number] = notice.backtrace.lines.first.number
|
154
|
-
end
|
155
|
-
|
156
|
-
result
|
157
|
-
end
|
158
|
-
|
159
|
-
private
|
160
|
-
|
161
|
-
def send_notice(notice)
|
162
|
-
if configuration.configured? && configuration.public?
|
163
|
-
if configuration.async?
|
164
|
-
configuration.async.call(notice)
|
165
|
-
nil # make sure we never set env["airbrake.error_id"] for async notices
|
166
|
-
else
|
167
|
-
sender.send_to_airbrake(notice)
|
168
|
-
end
|
169
|
-
else
|
170
|
-
report_notice_not_sent_for_configuration
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
def build_notice_for(exception, opts = {})
|
175
|
-
exception_classes = [exception.class.to_s]
|
176
|
-
exception = unwrap_exception(exception)
|
177
|
-
opts = opts.merge(:exception => exception) if exception.is_a?(Exception)
|
178
|
-
opts = opts.merge(exception.to_hash) if exception.respond_to?(:to_hash)
|
179
|
-
opts = opts.merge(:exception_classes => exception_classes)
|
180
|
-
Notice.new(configuration.merge(opts))
|
181
|
-
end
|
182
|
-
|
183
|
-
def unwrap_exception(exception)
|
184
|
-
if exception.respond_to?(:original_exception)
|
185
|
-
exception.original_exception
|
186
|
-
elsif exception.respond_to?(:continued_exception)
|
187
|
-
exception.continued_exception
|
188
|
-
end || exception
|
189
|
-
end
|
190
|
-
end
|
16
|
+
require 'airbrake/rails/railtie' if defined?(Rails)
|
191
17
|
end
|
18
|
+
|
19
|
+
require 'airbrake/rake/task_ext' if defined?(Rake)
|
20
|
+
require 'airbrake/resque/failure' if defined?(Resque)
|
21
|
+
require 'airbrake/sidekiq/error_handler' if defined?(Sidekiq)
|
22
|
+
require 'airbrake/delayed_job/plugin' if defined?(Delayed)
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'shellwords'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
if defined?(Capistrano::VERSION) &&
|
5
|
+
Gem::Version.new(Capistrano::VERSION).release >= Gem::Version.new('3.0.0')
|
6
|
+
namespace :airbrake do
|
7
|
+
desc "Notify Airbrake of the deploy"
|
8
|
+
task :deploy do
|
9
|
+
on roles(:all) do
|
10
|
+
within release_path do
|
11
|
+
with rails_env: fetch(:rails_env, fetch(:stage)) do
|
12
|
+
execute :rake, <<-CMD
|
13
|
+
airbrake:deploy USERNAME=#{Shellwords.shellescape(local_user)} \
|
14
|
+
ENVIRONMENT=#{fetch(:rails_env, fetch(:stage))} \
|
15
|
+
REVISION=#{fetch(:current_revision)} \
|
16
|
+
REPOSITORY=#{fetch(:repo_url)} \
|
17
|
+
VERSION=#{fetch(:app_version)}
|
18
|
+
CMD
|
19
|
+
|
20
|
+
info 'Notified Airbrake of the deploy'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
else
|
27
|
+
module Airbrake
|
28
|
+
##
|
29
|
+
# The Capistrano v2 integration.
|
30
|
+
module Capistrano
|
31
|
+
# rubocop:disable Metrics/AbcSize
|
32
|
+
def self.load_into(config)
|
33
|
+
config.load do
|
34
|
+
after 'deploy', 'airbrake:deploy'
|
35
|
+
after 'deploy:migrations', 'airbrake:deploy'
|
36
|
+
after 'deploy:cold', 'airbrake:deploy'
|
37
|
+
|
38
|
+
namespace :airbrake do
|
39
|
+
desc "Notify Airbrake of the deploy"
|
40
|
+
task :deploy, except: { no_release: true }, on_error: :continue do
|
41
|
+
FileUtils.cd(config.release_path) do
|
42
|
+
username = Shellwords.shellescape(ENV['USER'] || ENV['USERNAME'])
|
43
|
+
|
44
|
+
system(<<-CMD)
|
45
|
+
bundle exec rake airbrake:deploy \
|
46
|
+
USERNAME=#{username} \
|
47
|
+
ENVIRONMENT=#{fetch(:rails_env, 'production')} \
|
48
|
+
REVISION=#{current_revision.strip} \
|
49
|
+
REPOSITORY=#{repository} \
|
50
|
+
VERSION=#{fetch(:app_version, nil)}
|
51
|
+
CMD
|
52
|
+
end
|
53
|
+
|
54
|
+
logger.info 'Notified Airbrake of the deploy'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
# rubocop:enable Metrics/AbcSize
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
Airbrake::Capistrano.load_into(Capistrano::Configuration.instance)
|
64
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Delayed
|
2
|
+
module Plugins
|
3
|
+
##
|
4
|
+
# Provides integration with Delayed Job.
|
5
|
+
# rubocop:disable Lint/RescueException
|
6
|
+
class Airbrake < ::Delayed::Plugin
|
7
|
+
callbacks do |lifecycle|
|
8
|
+
lifecycle.around(:invoke_job) do |job, *args, &block|
|
9
|
+
begin
|
10
|
+
# Forward the call to the next callback in the callback chain
|
11
|
+
block.call(job, *args)
|
12
|
+
rescue Exception => exception
|
13
|
+
params = job.as_json.merge(
|
14
|
+
component: 'delayed_job',
|
15
|
+
action: job.payload_object.class.name
|
16
|
+
)
|
17
|
+
|
18
|
+
# If DelayedJob is used through ActiveJob, it contains extra info.
|
19
|
+
if job.payload_object.respond_to?(:job_data)
|
20
|
+
params[:active_job] = job.payload_object.job_data
|
21
|
+
end
|
22
|
+
|
23
|
+
::Airbrake.notify(exception, params)
|
24
|
+
raise exception
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
# rubocop:enable Lint/RescueException
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
if RUBY_ENGINE == 'jruby' && defined?(Delayed::Backend::ActiveRecord::Job)
|
34
|
+
##
|
35
|
+
# Workaround against JRuby bug:
|
36
|
+
# https://github.com/jruby/jruby/issues/3338
|
37
|
+
# rubocop:disable Style/ClassAndModuleChildren
|
38
|
+
class Delayed::Backend::ActiveRecord::Job
|
39
|
+
alias_method :old_to_ary, :to_ary
|
40
|
+
|
41
|
+
def to_ary
|
42
|
+
old_to_ary || [self]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
# rubocop:enable Style/ClassAndModuleChildren
|
46
|
+
end
|
47
|
+
|
48
|
+
Delayed::Worker.plugins << Delayed::Plugins::Airbrake
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Airbrake
|
2
|
+
module Rack
|
3
|
+
##
|
4
|
+
# Airbrake Rack middleware for Rails and Sinatra applications (or any other
|
5
|
+
# Rack-compliant app). Any errors raised by the upstream application will be
|
6
|
+
# delivered to Airbrake and re-raised.
|
7
|
+
#
|
8
|
+
# The middleware automatically sends information about the framework that
|
9
|
+
# uses it (name and version).
|
10
|
+
class Middleware
|
11
|
+
def initialize(app)
|
12
|
+
@app = app
|
13
|
+
end
|
14
|
+
|
15
|
+
##
|
16
|
+
# Rescues any exceptions, sends them to Airbrake and re-raises the
|
17
|
+
# exception.
|
18
|
+
# @param [Hash] env the Rack environment
|
19
|
+
def call(env)
|
20
|
+
# rubocop:disable Lint/RescueException
|
21
|
+
begin
|
22
|
+
response = @app.call(env)
|
23
|
+
rescue Exception => ex
|
24
|
+
notify_airbrake(ex, env)
|
25
|
+
raise ex
|
26
|
+
end
|
27
|
+
# rubocop:enable Lint/RescueException
|
28
|
+
|
29
|
+
# The internal framework middlewares store exceptions inside the Rack
|
30
|
+
# env. See: https://goo.gl/Kd694n
|
31
|
+
exception = env['action_dispatch.exception'] || env['sinatra.error']
|
32
|
+
notify_airbrake(exception, env) if exception
|
33
|
+
|
34
|
+
response
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def notify_airbrake(exception, env)
|
40
|
+
notice = NoticeBuilder.new(env).build_notice(exception)
|
41
|
+
Airbrake.notify(notice)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
module Airbrake
|
2
|
+
module Rack
|
3
|
+
##
|
4
|
+
# A helper class for filling notices with all sorts of useful information
|
5
|
+
# coming from the Rack environment.
|
6
|
+
class NoticeBuilder
|
7
|
+
##
|
8
|
+
# @return [String] the name of the host machine
|
9
|
+
HOSTNAME = Socket.gethostname.freeze
|
10
|
+
|
11
|
+
##
|
12
|
+
# @param [Hash{String=>Object}] rack_env The Rack environment
|
13
|
+
def initialize(rack_env)
|
14
|
+
@rack_env = rack_env
|
15
|
+
@request = ::Rack::Request.new(rack_env)
|
16
|
+
@controller = rack_env['action_controller.instance']
|
17
|
+
@session = @request.session
|
18
|
+
@user = Airbrake::Rack::User.extract(rack_env)
|
19
|
+
|
20
|
+
@framework_version =
|
21
|
+
if defined?(::Rails)
|
22
|
+
"Rails/#{::Rails.version}"
|
23
|
+
elsif defined?(::Sinatra)
|
24
|
+
"Sinatra/#{Sinatra::VERSION}"
|
25
|
+
else
|
26
|
+
"Rack.version/#{::Rack.version} Rack.release/#{::Rack.release}"
|
27
|
+
end.freeze
|
28
|
+
end
|
29
|
+
|
30
|
+
##
|
31
|
+
# Adds context, session, params and other fields based on the Rack env.
|
32
|
+
#
|
33
|
+
# @param [Exception] exception
|
34
|
+
# @return [Airbrake::Notice] the notice with extra information
|
35
|
+
def build_notice(exception)
|
36
|
+
notice = Airbrake.build_notice(exception)
|
37
|
+
|
38
|
+
add_context(notice)
|
39
|
+
add_session(notice)
|
40
|
+
add_params(notice)
|
41
|
+
|
42
|
+
notice
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def add_context(notice)
|
48
|
+
context = notice[:context]
|
49
|
+
|
50
|
+
context[:url] = @request.url
|
51
|
+
context[:userAgent] = @request.user_agent
|
52
|
+
context[:hostname] = HOSTNAME
|
53
|
+
|
54
|
+
if context.key?(:version)
|
55
|
+
context[:version] += " #{@framework_version}"
|
56
|
+
else
|
57
|
+
context[:version] = @framework_version
|
58
|
+
end
|
59
|
+
|
60
|
+
if @controller
|
61
|
+
context[:component] = @controller.controller_name
|
62
|
+
context[:action] = @controller.action_name
|
63
|
+
end
|
64
|
+
|
65
|
+
notice[:context].merge!(@user.to_hash) if @user
|
66
|
+
|
67
|
+
nil
|
68
|
+
end
|
69
|
+
|
70
|
+
def add_session(notice)
|
71
|
+
notice[:session] = @session if @session
|
72
|
+
end
|
73
|
+
|
74
|
+
def add_params(notice)
|
75
|
+
params = @request.env['action_dispatch.request.parameters']
|
76
|
+
notice[:params] = params if params
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|