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.
- checksums.yaml +4 -4
- 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/airbrake.rb +16 -185
- 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 +108 -323
- 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/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/rails.rb +0 -45
- 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/airbrake.cap +0 -28
- data/lib/airbrake/tasks.rb +0 -81
- 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/catcher_test.rb +0 -371
- data/test/integration.rb +0 -13
- 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.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,25 @@
|
|
1
|
+
##
|
2
|
+
# Creates the Airbrake initializer file for Rails apps.
|
3
|
+
#
|
4
|
+
# @example Invokation from terminal
|
5
|
+
# rails generate airbrake PROJECT_KEY PROJECT_ID [NAME]
|
6
|
+
#
|
7
|
+
class AirbrakeGenerator < Rails::Generators::Base
|
8
|
+
# Adds current directory to source paths, so we can find the template file.
|
9
|
+
source_root File.expand_path('..', __FILE__)
|
10
|
+
|
11
|
+
argument :project_id, required: false
|
12
|
+
argument :project_key, required: false
|
13
|
+
|
14
|
+
##
|
15
|
+
# Makes the NAME option optional, which allows to subclass from Base, so we
|
16
|
+
# can pass arguments to the ERB template.
|
17
|
+
#
|
18
|
+
# @see http://asciicasts.com/episodes/218-making-generators-in-rails-3
|
19
|
+
argument :name, type: :string, default: 'application'
|
20
|
+
|
21
|
+
desc 'Configures the Airbrake notifier with your project id and project key'
|
22
|
+
def generate_layout
|
23
|
+
template 'airbrake_initializer.rb.erb', 'config/initializers/airbrake.rb'
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# Airbrake is an online tool that provides robust exception tracking in your Rails
|
2
|
+
# applications. In doing so, it allows you to easily review errors, tie an error
|
3
|
+
# to an individual piece of code, and trace the cause back to recent
|
4
|
+
# changes. Airbrake enables for easy categorization, searching, and prioritization
|
5
|
+
# of exceptions so that when errors occur, your team can quickly determine the
|
6
|
+
# root cause.
|
7
|
+
#
|
8
|
+
# Configuration details:
|
9
|
+
# https://github.com/airbrake/airbrake-ruby#configuration
|
10
|
+
Airbrake.configure do |c|
|
11
|
+
# You must set both project_id & project_key. To find your project_id and
|
12
|
+
# project_key navigate to your project's General Settings and copy the values
|
13
|
+
# from the right sidebar.
|
14
|
+
# https://github.com/airbrake/airbrake-ruby#project_id--project_key
|
15
|
+
<% if project_id -%>
|
16
|
+
c.project_id = <%= project_id %>
|
17
|
+
<% else -%>
|
18
|
+
c.project_id = ENV['AIRBRAKE_PROJECT_ID']
|
19
|
+
<% end -%>
|
20
|
+
<% if project_key -%>
|
21
|
+
c.project_key = '<%= project_key %>'
|
22
|
+
<% else -%>
|
23
|
+
c.project_key = ENV['AIRBRAKE_API_KEY']
|
24
|
+
<% end -%>
|
25
|
+
|
26
|
+
# Configures the root directory of your project. Expects a String or a
|
27
|
+
# Pathname, which represents the path to your project. Providing this option
|
28
|
+
# helps us to filter out repetitive data from backtrace frames and link to
|
29
|
+
# GitHub files from our dashboard.
|
30
|
+
# https://github.com/airbrake/airbrake-ruby#root_directory
|
31
|
+
c.root_directory = Rails.root
|
32
|
+
|
33
|
+
# By default, Airbrake Ruby outputs to STDOUT. In Rails apps it makes sense to
|
34
|
+
# use the Rails' logger.
|
35
|
+
# https://github.com/airbrake/airbrake-ruby#logger
|
36
|
+
c.logger = Rails.logger
|
37
|
+
|
38
|
+
# Configures the environment the application is running in. Helps the Airbrake
|
39
|
+
# dashboard to distinguish between exceptions occurring in different
|
40
|
+
# environments. By default, it's not set.
|
41
|
+
# https://github.com/airbrake/airbrake-ruby#environment
|
42
|
+
c.environment = Rails.env
|
43
|
+
|
44
|
+
# Setting this option allows Airbrake to filter exceptions occurring in
|
45
|
+
# unwanted environments such as :test. By default, it is equal to an empty
|
46
|
+
# Array, which means Airbrake Ruby sends exceptions occurring in all
|
47
|
+
# environments.
|
48
|
+
# https://github.com/airbrake/airbrake-ruby#ignore_environments
|
49
|
+
c.ignore_environments = %w(test)
|
50
|
+
end
|
51
|
+
|
52
|
+
# If Airbrake doesn't send any expected exceptions, we suggest to uncomment the
|
53
|
+
# line below. It might simplify debugging of background Airbrake workers, which
|
54
|
+
# can silently die.
|
55
|
+
# Thread.abort_on_exception = ['test', 'development'].include?(Rails.env)
|
File without changes
|
@@ -0,0 +1,17 @@
|
|
1
|
+
DummyApp = Rack::Builder.new do
|
2
|
+
use Rack::ShowExceptions
|
3
|
+
use Airbrake::Rack::Middleware
|
4
|
+
use Warden::Manager
|
5
|
+
|
6
|
+
map '/' do
|
7
|
+
run(
|
8
|
+
proc do |_env|
|
9
|
+
[200, { 'Content-Type' => 'text/plain' }, ['Hello from index']]
|
10
|
+
end
|
11
|
+
)
|
12
|
+
end
|
13
|
+
|
14
|
+
map '/crash' do
|
15
|
+
run proc { |_env| raise AirbrakeTestError }
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,150 @@
|
|
1
|
+
class DummyApp < Rails::Application
|
2
|
+
# Rails requires these two keys.
|
3
|
+
config.session_store :cookie_store, key: 'jiez4Mielu1AiHugog3shiiPhe3lai3faer'
|
4
|
+
config.secret_token = 'ni6aeph6aeriBiphesh8omahv6cohpue5Quah5ceiMohtuvei8'
|
5
|
+
|
6
|
+
if Gem::Version.new(Rails.version) > Gem::Version.new('3.2.0')
|
7
|
+
config.secret_key_base = '62773890cad9d9d584b57320f8612f8f7378a90aadcabc6ee'
|
8
|
+
end
|
9
|
+
|
10
|
+
# Configure a logger, without it the tests can't run.
|
11
|
+
vsn = Rails.version.split('').values_at(0, 2).join('')
|
12
|
+
log_path = File.join(File.dirname(__FILE__), 'logs', "#{vsn}.log")
|
13
|
+
config.logger = Logger.new(log_path)
|
14
|
+
Rails.logger = config.logger
|
15
|
+
|
16
|
+
config.active_support.deprecation = :stderr
|
17
|
+
|
18
|
+
config.middleware.use Warden::Manager
|
19
|
+
|
20
|
+
# In Rails 4.2.x Active Record suppresses errors raised within
|
21
|
+
# 'after_rollback' & 'after_commit' callbacks and only print them to the
|
22
|
+
# logs. In the next version, these errors will no longer be suppressed.
|
23
|
+
# Instead, the errors will propagate normally just like in other Active Record
|
24
|
+
# callbacks.
|
25
|
+
config.active_record.raise_in_transactional_callbacks = true if vsn == '42'
|
26
|
+
|
27
|
+
# Silences the warning, which says 'config.eager_load is set to nil'.
|
28
|
+
config.eager_load = false
|
29
|
+
|
30
|
+
routes.append do
|
31
|
+
get '/' => 'dummy#index'
|
32
|
+
get '/crash' => 'dummy#crash'
|
33
|
+
get '/notify_airbrake_helper' => 'dummy#notify_airbrake_helper'
|
34
|
+
get '/notify_airbrake_sync_helper' => 'dummy#notify_airbrake_sync_helper'
|
35
|
+
get '/active_record_after_commit' => 'dummy#active_record_after_commit'
|
36
|
+
get '/active_record_after_rollback' => 'dummy#active_record_after_rollback'
|
37
|
+
get '/active_job' => 'dummy#active_job'
|
38
|
+
get '/resque' => 'dummy#resque'
|
39
|
+
get '/delayed_job' => 'dummy#delayed_job'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class Book < ActiveRecord::Base
|
44
|
+
after_commit :raise_error_after_commit
|
45
|
+
after_rollback :raise_error_after_rollback
|
46
|
+
|
47
|
+
def raise_error_after_commit
|
48
|
+
raise AirbrakeTestError, 'after_commit'
|
49
|
+
end
|
50
|
+
|
51
|
+
def raise_error_after_rollback
|
52
|
+
raise AirbrakeTestError, 'after_rollback'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# ActiveJob.
|
57
|
+
if Gem::Version.new(Rails.version) >= Gem::Version.new('4.2')
|
58
|
+
class BingoJob < ActiveJob::Base
|
59
|
+
queue_as :bingo
|
60
|
+
|
61
|
+
def perform(*_args)
|
62
|
+
raise AirbrakeTestError, 'active_job error'
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# Resque.
|
68
|
+
class BingoWorker
|
69
|
+
@queue = :bingo_workers_queue
|
70
|
+
|
71
|
+
def self.perform(_bango, _bongo)
|
72
|
+
raise AirbrakeTestError, 'resque error'
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# DelayedJob.
|
77
|
+
BangoJob = Struct.new(:bingo, :bongo) do
|
78
|
+
def perform
|
79
|
+
raise AirbrakeTestError, 'delayed_job error'
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
class DummyController < ActionController::Base
|
84
|
+
layout 'application'
|
85
|
+
|
86
|
+
self.view_paths = [
|
87
|
+
ActionView::FixtureResolver.new(
|
88
|
+
'layouts/application.html.erb' => '<%= yield %>',
|
89
|
+
'dummy/index.html.erb' => 'Hello from index',
|
90
|
+
'dummy/notify_airbrake_helper.html.erb' => 'notify_airbrake_helper',
|
91
|
+
'dummy/notify_airbrake_sync_helper.html.erb' => 'notify_airbrake_helper_sync',
|
92
|
+
'dummy/active_record_after_commit.html.erb' => 'active_record_after_commit',
|
93
|
+
'dummy/active_record_after_rollback.html.erb' => 'active_record_after_rollback',
|
94
|
+
'dummy/active_job.html.erb' => 'active_job',
|
95
|
+
'dummy/resque.html.erb' => 'resque',
|
96
|
+
'dummy/delayed_job.html.erb' => 'delayed_job'
|
97
|
+
)
|
98
|
+
]
|
99
|
+
|
100
|
+
def index
|
101
|
+
end
|
102
|
+
|
103
|
+
def crash
|
104
|
+
raise AirbrakeTestError
|
105
|
+
end
|
106
|
+
|
107
|
+
def notify_airbrake_helper
|
108
|
+
notify_airbrake(AirbrakeTestError.new)
|
109
|
+
end
|
110
|
+
|
111
|
+
def notify_airbrake_sync_helper
|
112
|
+
notify_airbrake_sync(AirbrakeTestError.new)
|
113
|
+
end
|
114
|
+
|
115
|
+
def active_record_after_commit
|
116
|
+
Book.create(title: 'Bingo')
|
117
|
+
end
|
118
|
+
|
119
|
+
def active_record_after_rollback
|
120
|
+
Book.transaction do
|
121
|
+
Book.create(title: 'Bango')
|
122
|
+
raise ActiveRecord::Rollback
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def active_job
|
127
|
+
BingoJob.perform_later('bango', 'bongo')
|
128
|
+
end
|
129
|
+
|
130
|
+
def resque
|
131
|
+
Resque.enqueue(BingoWorker, 'bango', 'bongo')
|
132
|
+
end
|
133
|
+
|
134
|
+
def delayed_job
|
135
|
+
Delayed::Job.enqueue(BangoJob.new('bingo', 'bongo'))
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
# Initializes middlewares and such.
|
140
|
+
DummyApp.initialize!
|
141
|
+
|
142
|
+
ActiveRecord::Base.connection.create_table(:books) do |t|
|
143
|
+
t.string(:title)
|
144
|
+
end
|
145
|
+
|
146
|
+
ActiveRecord::Migration.verbose = false
|
147
|
+
require 'generators/delayed_job/templates/migration'
|
148
|
+
ActiveRecord::Schema.define do
|
149
|
+
CreateDelayedJobs.up
|
150
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# Keep this before any task definitions to collect extra info about tasks.
|
2
|
+
# Without this line the tests will fail.
|
3
|
+
Rake::TaskManager.record_task_metadata = true
|
4
|
+
|
5
|
+
namespace :bingo do
|
6
|
+
# This task contains *maximum* amount of information.
|
7
|
+
desc 'Dummy description'
|
8
|
+
task :bango, [:dummy_arg] => [:environment] do |_t, _args|
|
9
|
+
raise AirbrakeTestError
|
10
|
+
end
|
11
|
+
|
12
|
+
# This task contains *minimum* amount of information.
|
13
|
+
task :bongo do
|
14
|
+
raise AirbrakeTestError
|
15
|
+
end
|
16
|
+
|
17
|
+
task :environment do
|
18
|
+
# No-op.
|
19
|
+
end
|
20
|
+
end
|