rollbar 2.26.0 → 3.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/pull_request_template.md +34 -0
- data/.github/workflows/ci.yml +104 -0
- data/.rubocop.yml +52 -36
- data/Gemfile +25 -29
- data/README.md +32 -8
- data/data/rollbar.snippet.js +1 -1
- data/docs/configuration.md +7 -0
- data/gemfiles/rails30.gemfile +17 -35
- data/gemfiles/rails31.gemfile +20 -37
- data/gemfiles/rails32.gemfile +13 -31
- data/gemfiles/rails40.gemfile +12 -32
- data/gemfiles/rails41.gemfile +11 -31
- data/gemfiles/rails42.gemfile +11 -35
- data/gemfiles/rails50.gemfile +14 -32
- data/gemfiles/rails51.gemfile +13 -31
- data/gemfiles/rails52.gemfile +10 -19
- data/gemfiles/rails60.gemfile +10 -25
- data/gemfiles/rails61.gemfile +52 -0
- data/gemfiles/rails70.gemfile +52 -0
- data/lib/generators/rollbar/rollbar_generator.rb +18 -14
- data/lib/rails/rollbar_runner.rb +8 -19
- data/lib/rollbar/capistrano.rb +17 -9
- data/lib/rollbar/capistrano3.rb +8 -2
- data/lib/rollbar/capistrano_tasks.rb +44 -8
- data/lib/rollbar/configuration.rb +122 -88
- data/lib/rollbar/delay/shoryuken.rb +4 -3
- data/lib/rollbar/delay/sidekiq.rb +3 -1
- data/lib/rollbar/delay/sucker_punch.rb +1 -2
- data/lib/rollbar/delay/thread.rb +3 -2
- data/lib/rollbar/deploy.rb +6 -7
- data/lib/rollbar/encoding/encoder.rb +7 -3
- data/lib/rollbar/encoding.rb +2 -7
- data/lib/rollbar/exception_reporter.rb +17 -8
- data/lib/rollbar/item/backtrace.rb +10 -8
- data/lib/rollbar/item/frame.rb +6 -5
- data/lib/rollbar/item/locals.rb +5 -2
- data/lib/rollbar/item.rb +60 -38
- data/lib/rollbar/json.rb +1 -1
- data/lib/rollbar/language_support.rb +0 -6
- data/lib/rollbar/lazy_store.rb +3 -7
- data/lib/rollbar/logger.rb +2 -0
- data/lib/rollbar/logger_proxy.rb +3 -1
- data/lib/rollbar/middleware/js/json_value.rb +15 -5
- data/lib/rollbar/middleware/js.rb +59 -37
- data/lib/rollbar/middleware/rack/builder.rb +3 -3
- data/lib/rollbar/middleware/rack/test_session.rb +3 -3
- data/lib/rollbar/middleware/rack.rb +4 -4
- data/lib/rollbar/middleware/rails/rollbar.rb +9 -6
- data/lib/rollbar/middleware/rails/show_exceptions.rb +8 -4
- data/lib/rollbar/notifier/trace_with_bindings.rb +13 -3
- data/lib/rollbar/notifier.rb +180 -136
- data/lib/rollbar/plugin.rb +8 -8
- data/lib/rollbar/plugins/active_job.rb +15 -2
- data/lib/rollbar/plugins/delayed_job/plugin.rb +14 -3
- data/lib/rollbar/plugins/goalie.rb +27 -16
- data/lib/rollbar/plugins/rails/controller_methods.rb +18 -14
- data/lib/rollbar/plugins/rails/railtie30.rb +2 -1
- data/lib/rollbar/plugins/rails/railtie32.rb +2 -1
- data/lib/rollbar/plugins/rails/railtie_mixin.rb +2 -2
- data/lib/rollbar/plugins/rails.rb +5 -2
- data/lib/rollbar/plugins/rake.rb +2 -1
- data/lib/rollbar/plugins/sidekiq/plugin.rb +39 -21
- data/lib/rollbar/plugins/sidekiq.rb +1 -1
- data/lib/rollbar/plugins/thread.rb +8 -7
- data/lib/rollbar/plugins/validations.rb +3 -1
- data/lib/rollbar/rake_tasks.rb +1 -2
- data/lib/rollbar/request_data_extractor.rb +48 -19
- data/lib/rollbar/rollbar_test.rb +9 -118
- data/lib/rollbar/scrubbers/params.rb +13 -7
- data/lib/rollbar/scrubbers/url.rb +56 -17
- data/lib/rollbar/scrubbers.rb +1 -1
- data/lib/rollbar/truncation/remove_any_key_strategy.rb +4 -1
- data/lib/rollbar/truncation/remove_extra_strategy.rb +3 -1
- data/lib/rollbar/util/hash.rb +14 -7
- data/lib/rollbar/util/ip_anonymizer.rb +1 -1
- data/lib/rollbar/util.rb +19 -13
- data/lib/rollbar/version.rb +1 -1
- data/lib/rollbar.rb +12 -7
- data/lib/tasks/benchmark.rake +2 -1
- data/rollbar.gemspec +5 -3
- metadata +17 -12
- data/.travis.yml +0 -284
- data/lib/rollbar/encoding/legacy_encoder.rb +0 -20
- /data/lib/generators/rollbar/templates/{initializer.rb → initializer.erb} +0 -0
@@ -11,29 +11,40 @@ Rollbar.plugins.define('goalie') do
|
|
11
11
|
begin
|
12
12
|
controller = env['action_controller.instance']
|
13
13
|
request_data = begin
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
controller.rollbar_request_data
|
15
|
+
rescue StandardError
|
16
|
+
nil
|
17
|
+
end
|
18
18
|
person_data = begin
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
exception_data = Rollbar.scope(
|
19
|
+
controller.rollbar_person_data
|
20
|
+
rescue StandardError
|
21
|
+
nil
|
22
|
+
end
|
23
|
+
exception_data = Rollbar.scope(
|
24
|
+
:request => request_data,
|
25
|
+
:person => person_data
|
26
|
+
).error(exception, :use_exception_level_filters => true)
|
24
27
|
rescue StandardError => e
|
25
|
-
|
28
|
+
message = "[Rollbar] Exception while reporting exception to Rollbar: #{e}"
|
29
|
+
Rollbar.log_warning(message)
|
26
30
|
end
|
27
31
|
|
28
32
|
# if an exception was reported, save uuid in the env
|
29
33
|
# so it can be displayed to the user on the error page
|
30
|
-
|
34
|
+
case exception_data
|
35
|
+
when Hash
|
31
36
|
env['rollbar.exception_uuid'] = exception_data[:uuid]
|
32
|
-
Rollbar.log_info
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
Rollbar.log_info
|
37
|
+
Rollbar.log_info(
|
38
|
+
"[Rollbar] Exception uuid saved in env: #{exception_data[:uuid]}"
|
39
|
+
)
|
40
|
+
when 'disabled'
|
41
|
+
Rollbar.log_info(
|
42
|
+
'[Rollbar] Exception not reported because Rollbar is disabled'
|
43
|
+
)
|
44
|
+
when 'ignored'
|
45
|
+
Rollbar.log_info(
|
46
|
+
'[Rollbar] Exception not reported because it was ignored'
|
47
|
+
)
|
37
48
|
end
|
38
49
|
|
39
50
|
# now continue as normal
|
@@ -7,30 +7,34 @@ module Rollbar
|
|
7
7
|
include RequestDataExtractor
|
8
8
|
|
9
9
|
def rollbar_person_data
|
10
|
-
|
10
|
+
user = nil
|
11
|
+
unless Rollbar::Util.method_in_stack_twice(:rollbar_person_data, __FILE__)
|
12
|
+
user = send(Rollbar.configuration.person_method)
|
13
|
+
end
|
14
|
+
|
11
15
|
# include id, username, email if non-empty
|
12
16
|
if user
|
13
17
|
{
|
14
18
|
:id => (begin
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
+
user.send(Rollbar.configuration.person_id_method)
|
20
|
+
rescue StandardError
|
21
|
+
nil
|
22
|
+
end),
|
19
23
|
:username => (begin
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
+
user.send(Rollbar.configuration.person_username_method)
|
25
|
+
rescue StandardError
|
26
|
+
nil
|
27
|
+
end),
|
24
28
|
:email => (begin
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
+
user.send(Rollbar.configuration.person_email_method)
|
30
|
+
rescue StandardError
|
31
|
+
nil
|
32
|
+
end)
|
29
33
|
}
|
30
34
|
else
|
31
35
|
{}
|
32
36
|
end
|
33
|
-
rescue
|
37
|
+
rescue NameError
|
34
38
|
{}
|
35
39
|
end
|
36
40
|
|
@@ -11,7 +11,8 @@ module Rollbar
|
|
11
11
|
|
12
12
|
app.config.middleware.insert_after ActionDispatch::ShowExceptions,
|
13
13
|
Rollbar::Middleware::Rails::RollbarMiddleware
|
14
|
-
ActionDispatch::ShowExceptions.send(:include,
|
14
|
+
ActionDispatch::ShowExceptions.send(:include,
|
15
|
+
Rollbar::Middleware::Rails::ShowExceptions)
|
15
16
|
end
|
16
17
|
end
|
17
18
|
end
|
@@ -11,7 +11,8 @@ module Rollbar
|
|
11
11
|
|
12
12
|
app.config.middleware.insert_after ActionDispatch::DebugExceptions,
|
13
13
|
Rollbar::Middleware::Rails::RollbarMiddleware
|
14
|
-
ActionDispatch::DebugExceptions.send(:include,
|
14
|
+
ActionDispatch::DebugExceptions.send(:include,
|
15
|
+
Rollbar::Middleware::Rails::ShowExceptions)
|
15
16
|
end
|
16
17
|
end
|
17
18
|
end
|
@@ -16,9 +16,9 @@ module Rollbar
|
|
16
16
|
config.framework = "Rails: #{::Rails::VERSION::STRING}"
|
17
17
|
config.filepath ||= begin
|
18
18
|
if ::Rails.application.class.respond_to?(:module_parent_name)
|
19
|
-
::Rails.application.class.module_parent_name
|
19
|
+
"#{::Rails.application.class.module_parent_name}.rollbar"
|
20
20
|
else
|
21
|
-
::Rails.application.class.parent_name
|
21
|
+
"#{::Rails.application.class.parent_name}.rollbar"
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -39,7 +39,8 @@ Rollbar.plugins.define('rails-rollbar.js') do
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def after_secure_headers(&block)
|
42
|
-
Rollbar::Railtie.initializer('rollbar.js.frameworks.rails',
|
42
|
+
Rollbar::Railtie.initializer('rollbar.js.frameworks.rails',
|
43
|
+
:after => 'secure_headers.middleware', &block)
|
43
44
|
end
|
44
45
|
|
45
46
|
def plugin_execute_proc_body(plugin)
|
@@ -52,7 +53,8 @@ Rollbar.plugins.define('rails-rollbar.js') do
|
|
52
53
|
:options => Rollbar.configuration.js_options,
|
53
54
|
:enabled => Rollbar.configuration.js_enabled
|
54
55
|
}
|
55
|
-
::Rails.configuration.middleware.use(::Rollbar::Middleware::Js,
|
56
|
+
::Rails.configuration.middleware.use(::Rollbar::Middleware::Js,
|
57
|
+
config)
|
56
58
|
end
|
57
59
|
end
|
58
60
|
end
|
@@ -62,6 +64,7 @@ Rollbar.plugins.define('rails-rollbar.js') do
|
|
62
64
|
begin
|
63
65
|
require 'secure_headers'
|
64
66
|
rescue LoadError
|
67
|
+
# Skip loading
|
65
68
|
end
|
66
69
|
|
67
70
|
defined?(::SecureHeaders::Middleware)
|
data/lib/rollbar/plugins/rake.rb
CHANGED
@@ -40,7 +40,8 @@ Rollbar.plugins.define('rake') do
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def self.skip_patch
|
43
|
-
warn('[Rollbar] Rollbar is disabled for Rake tasks since your Rake
|
43
|
+
warn('[Rollbar] Rollbar is disabled for Rake tasks since your Rake ' \
|
44
|
+
'version is under 0.9.x. Please upgrade to 0.9.x or higher.')
|
44
45
|
end
|
45
46
|
|
46
47
|
def self.patch?
|
@@ -4,21 +4,39 @@ module Rollbar
|
|
4
4
|
class Sidekiq
|
5
5
|
PARAM_BLACKLIST = %w[backtrace error_backtrace error_message error_class].freeze
|
6
6
|
|
7
|
-
class
|
8
|
-
def call(_worker,
|
9
|
-
Rollbar.reset_notifier!
|
7
|
+
class ResetScope
|
8
|
+
def call(_worker, msg, _queue, &block)
|
9
|
+
Rollbar.reset_notifier! # clears scope
|
10
10
|
|
11
|
-
yield
|
11
|
+
return yield unless Rollbar.configuration.sidekiq_use_scoped_block
|
12
|
+
|
13
|
+
Rollbar.scoped(Rollbar::Sidekiq.job_scope(msg), &block)
|
12
14
|
end
|
13
15
|
end
|
14
16
|
|
15
|
-
def self.handle_exception(
|
16
|
-
|
17
|
-
|
17
|
+
def self.handle_exception(msg, e)
|
18
|
+
return if skip_report?(msg, e)
|
19
|
+
|
20
|
+
Rollbar.scope(job_scope(msg)).error(e, :use_exception_level_filters => true)
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.skip_report?(msg, _e)
|
24
|
+
job_hash = job_hash_from_msg(msg)
|
25
|
+
|
26
|
+
return false if job_hash.nil?
|
27
|
+
|
28
|
+
# when rollbar middleware catches, sidekiq's retry_job processor hasn't set
|
29
|
+
# the retry_count for the current job yet, so adding 1 gives the actual retry count
|
30
|
+
actual_retry_count = job_hash.fetch('retry_count', -1) + 1
|
31
|
+
job_hash['retry'] && actual_retry_count < ::Rollbar.configuration.sidekiq_threshold
|
32
|
+
end
|
18
33
|
|
34
|
+
def self.job_scope(msg)
|
19
35
|
scope = {
|
20
36
|
:framework => "Sidekiq: #{::Sidekiq::VERSION}"
|
21
37
|
}
|
38
|
+
job_hash = job_hash_from_msg(msg)
|
39
|
+
|
22
40
|
unless job_hash.nil?
|
23
41
|
params = job_hash.reject { |k| PARAM_BLACKLIST.include?(k) }
|
24
42
|
scope[:request] = { :params => scrub_params(params) }
|
@@ -26,34 +44,34 @@ module Rollbar
|
|
26
44
|
scope[:queue] = params['queue']
|
27
45
|
end
|
28
46
|
|
29
|
-
|
47
|
+
scope
|
30
48
|
end
|
31
49
|
|
32
50
|
def self.scrub_params(params)
|
33
51
|
options = {
|
34
52
|
:params => params,
|
35
|
-
:config => Rollbar.configuration.scrub_fields
|
53
|
+
:config => Rollbar.configuration.scrub_fields,
|
54
|
+
:whitelist => Rollbar.configuration.scrub_whitelist
|
36
55
|
}
|
37
56
|
|
38
57
|
Rollbar::Scrubbers::Params.call(options)
|
39
58
|
end
|
40
59
|
|
41
|
-
|
42
|
-
|
60
|
+
# see https://github.com/mperham/sidekiq/wiki/Middleware#server-middleware
|
61
|
+
def call(_worker, msg, _queue, &block)
|
62
|
+
Rollbar.reset_notifier! # clears scope
|
43
63
|
|
44
|
-
|
45
|
-
# the retry_count for the current job yet, so adding 1 gives the actual retry count
|
46
|
-
actual_retry_count = job_hash.fetch('retry_count', -1) + 1
|
47
|
-
job_hash['retry'] && actual_retry_count < ::Rollbar.configuration.sidekiq_threshold
|
48
|
-
end
|
49
|
-
|
50
|
-
def call(_worker, msg, _queue)
|
51
|
-
Rollbar.reset_notifier!
|
64
|
+
return yield unless Rollbar.configuration.sidekiq_use_scoped_block
|
52
65
|
|
53
|
-
|
54
|
-
rescue Exception => e
|
66
|
+
Rollbar.scoped(Rollbar::Sidekiq.job_scope(msg), &block)
|
67
|
+
rescue Exception => e # rubocop:disable Lint/RescueException
|
55
68
|
Rollbar::Sidekiq.handle_exception(msg, e)
|
56
69
|
raise
|
57
70
|
end
|
71
|
+
|
72
|
+
def self.job_hash_from_msg(msg)
|
73
|
+
msg && (msg[:job] || msg)
|
74
|
+
end
|
75
|
+
private_class_method :job_hash_from_msg
|
58
76
|
end
|
59
77
|
end
|
@@ -9,7 +9,7 @@ Rollbar.plugins.define('sidekiq >= 3') do
|
|
9
9
|
|
10
10
|
Sidekiq.configure_server do |config|
|
11
11
|
config.server_middleware do |chain|
|
12
|
-
chain.add Rollbar::Sidekiq::
|
12
|
+
chain.add Rollbar::Sidekiq::ResetScope
|
13
13
|
end
|
14
14
|
|
15
15
|
config.error_handlers << proc do |e, context|
|
@@ -1,13 +1,14 @@
|
|
1
1
|
Rollbar.plugins.define('thread') do
|
2
|
-
|
3
|
-
|
4
|
-
def
|
2
|
+
module Rollbar
|
3
|
+
module ThreadPlugin
|
4
|
+
def initialize(*args)
|
5
5
|
self[:_rollbar_notifier] ||= Rollbar.notifier.scope
|
6
|
-
|
6
|
+
super
|
7
7
|
end
|
8
|
-
|
9
|
-
alias_method :initialize_without_rollbar, :initialize
|
10
|
-
alias_method :initialize, :initialize_with_rollbar
|
11
8
|
end
|
12
9
|
end
|
10
|
+
|
11
|
+
execute do
|
12
|
+
Thread.send(:prepend, Rollbar::ThreadPlugin)
|
13
|
+
end
|
13
14
|
end
|
@@ -17,7 +17,9 @@ Rollbar.plugins.define('active_model') do
|
|
17
17
|
module ActiveRecordExtension
|
18
18
|
def report_validation_errors_to_rollbar
|
19
19
|
errors.full_messages.each do |error|
|
20
|
-
Rollbar.log_info
|
20
|
+
Rollbar.log_info(
|
21
|
+
"[Rollbar] Reporting form validation error: #{error} for #{self}"
|
22
|
+
)
|
21
23
|
Rollbar.warning("Form Validation Error: #{error} for #{self}")
|
22
24
|
end
|
23
25
|
end
|
data/lib/rollbar/rake_tasks.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
|
-
|
2
1
|
namespace :rollbar do
|
3
|
-
desc 'Verify your gem installation by sending a test
|
2
|
+
desc 'Verify your gem installation by sending a test message to Rollbar'
|
4
3
|
task :test => [:environment] do
|
5
4
|
rollbar_dir = Gem.loaded_specs['rollbar'].full_gem_path
|
6
5
|
require "#{rollbar_dir}/lib/rollbar/rollbar_test"
|
@@ -19,10 +19,10 @@ module Rollbar
|
|
19
19
|
else
|
20
20
|
controller = env['action_controller.instance']
|
21
21
|
person_data = begin
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
controller.rollbar_person_data
|
23
|
+
rescue StandardError
|
24
|
+
{}
|
25
|
+
end
|
26
26
|
end
|
27
27
|
|
28
28
|
person_data
|
@@ -34,7 +34,8 @@ module Rollbar
|
|
34
34
|
|
35
35
|
get_params = scrub_params(rollbar_get_params(rack_req), sensitive_params)
|
36
36
|
post_params = scrub_params(rollbar_post_params(rack_req), sensitive_params)
|
37
|
-
raw_body_params = scrub_params(mergeable_raw_body_params(rack_req),
|
37
|
+
raw_body_params = scrub_params(mergeable_raw_body_params(rack_req),
|
38
|
+
sensitive_params)
|
38
39
|
cookies = scrub_params(rollbar_request_cookies(rack_req), sensitive_params)
|
39
40
|
session = scrub_params(rollbar_request_session(env), sensitive_params)
|
40
41
|
route_params = scrub_params(rollbar_route_params(env), sensitive_params)
|
@@ -54,7 +55,10 @@ module Rollbar
|
|
54
55
|
:method => rollbar_request_method(env)
|
55
56
|
}
|
56
57
|
|
57
|
-
|
58
|
+
if env['action_dispatch.request_id']
|
59
|
+
data[:request_id] =
|
60
|
+
env['action_dispatch.request_id']
|
61
|
+
end
|
58
62
|
|
59
63
|
data
|
60
64
|
end
|
@@ -87,9 +91,10 @@ module Rollbar
|
|
87
91
|
def mergeable_raw_body_params(rack_req)
|
88
92
|
raw_body_params = rollbar_raw_body_params(rack_req)
|
89
93
|
|
90
|
-
|
94
|
+
case raw_body_params
|
95
|
+
when Hash
|
91
96
|
raw_body_params
|
92
|
-
|
97
|
+
when Array
|
93
98
|
{ 'body.multi' => raw_body_params }
|
94
99
|
else
|
95
100
|
{ 'body.value' => raw_body_params }
|
@@ -109,13 +114,17 @@ module Rollbar
|
|
109
114
|
{ name => Rollbar::Scrubbers.scrub_value(env[header]) }
|
110
115
|
elsif name == 'X-Forwarded-For' && !Rollbar.configuration.collect_user_ip
|
111
116
|
{}
|
112
|
-
elsif name == 'X-Forwarded-For' &&
|
117
|
+
elsif name == 'X-Forwarded-For' &&
|
118
|
+
Rollbar.configuration.collect_user_ip &&
|
119
|
+
Rollbar.configuration.anonymize_user_ip
|
113
120
|
ips = env[header].sub(' ', '').split(',')
|
114
121
|
ips = ips.map { |ip| Rollbar::Util::IPAnonymizer.anonymize_ip(ip) }
|
115
122
|
{ name => ips.join(', ') }
|
116
123
|
elsif name == 'X-Real-Ip' && !Rollbar.configuration.collect_user_ip
|
117
124
|
{}
|
118
|
-
elsif name == 'X-Real-Ip' &&
|
125
|
+
elsif name == 'X-Real-Ip' &&
|
126
|
+
Rollbar.configuration.collect_user_ip &&
|
127
|
+
Rollbar.configuration.anonymize_user_ip
|
119
128
|
{ name => Rollbar::Util::IPAnonymizer.anonymize_ip(env[header]) }
|
120
129
|
else
|
121
130
|
{ name => env[header] }
|
@@ -131,15 +140,15 @@ module Rollbar
|
|
131
140
|
host = host.split(',').first.strip unless host.empty?
|
132
141
|
|
133
142
|
path = env['ORIGINAL_FULLPATH'] || env['REQUEST_URI']
|
134
|
-
|
135
|
-
|
136
|
-
|
143
|
+
query = env['QUERY_STRING'].to_s.empty? ? nil : "?#{env['QUERY_STRING']}"
|
144
|
+
path ||= "#{env['SCRIPT_NAME']}#{env['PATH_INFO']}#{query}"
|
145
|
+
path = "/#{path}" if !(path.nil? || path.empty?) && (path.to_s.slice(0, 1) != '/')
|
137
146
|
|
138
147
|
port = env['HTTP_X_FORWARDED_PORT']
|
139
148
|
if port && !(!scheme.nil? && scheme.casecmp('http').zero? && port.to_i == 80) && \
|
140
149
|
!(!scheme.nil? && scheme.casecmp('https').zero? && port.to_i == 443) && \
|
141
150
|
!(host.include? ':')
|
142
|
-
host = host
|
151
|
+
host = "#{host}:#{port}"
|
143
152
|
end
|
144
153
|
|
145
154
|
[scheme, '://', host, path].join
|
@@ -148,7 +157,11 @@ module Rollbar
|
|
148
157
|
def rollbar_user_ip(env)
|
149
158
|
return nil unless Rollbar.configuration.collect_user_ip
|
150
159
|
|
151
|
-
user_ip_string = (
|
160
|
+
user_ip_string = (user_ip_at_configured_key(env) ||
|
161
|
+
env['action_dispatch.remote_ip'] ||
|
162
|
+
env['HTTP_X_REAL_IP'] ||
|
163
|
+
x_forwarded_for_client(env['HTTP_X_FORWARDED_FOR']) ||
|
164
|
+
env['REMOTE_ADDR']).to_s
|
152
165
|
|
153
166
|
user_ip_string = Rollbar::Util::IPAnonymizer.anonymize_ip(user_ip_string)
|
154
167
|
|
@@ -157,6 +170,12 @@ module Rollbar
|
|
157
170
|
nil
|
158
171
|
end
|
159
172
|
|
173
|
+
def user_ip_at_configured_key(env)
|
174
|
+
return nil unless Rollbar.configuration.user_ip_rack_env_key
|
175
|
+
|
176
|
+
env[Rollbar.configuration.user_ip_rack_env_key]
|
177
|
+
end
|
178
|
+
|
160
179
|
def x_forwarded_for_client(header_value)
|
161
180
|
return nil unless header_value
|
162
181
|
|
@@ -195,7 +214,7 @@ module Rollbar
|
|
195
214
|
return {} unless correct_method
|
196
215
|
return {} unless json_request?(rack_req)
|
197
216
|
|
198
|
-
raw_body = rack_req.body
|
217
|
+
raw_body = read_raw_body(rack_req.body)
|
199
218
|
begin
|
200
219
|
Rollbar::JSON.load(raw_body)
|
201
220
|
rescue StandardError
|
@@ -203,8 +222,15 @@ module Rollbar
|
|
203
222
|
end
|
204
223
|
rescue StandardError
|
205
224
|
{}
|
206
|
-
|
207
|
-
|
225
|
+
end
|
226
|
+
|
227
|
+
def read_raw_body(body)
|
228
|
+
return {} unless body.respond_to?(:rewind)
|
229
|
+
|
230
|
+
body.rewind
|
231
|
+
raw_body = body.read
|
232
|
+
body.rewind
|
233
|
+
raw_body
|
208
234
|
end
|
209
235
|
|
210
236
|
def json_request?(rack_req)
|
@@ -247,7 +273,10 @@ module Rollbar
|
|
247
273
|
end
|
248
274
|
|
249
275
|
def sensitive_headers_list
|
250
|
-
|
276
|
+
unless Rollbar.configuration.scrub_headers &&
|
277
|
+
Rollbar.configuration.scrub_headers.is_a?(Array)
|
278
|
+
return []
|
279
|
+
end
|
251
280
|
|
252
281
|
# Normalize into the expected matching format
|
253
282
|
Rollbar.configuration.scrub_headers.map do |header|
|
data/lib/rollbar/rollbar_test.rb
CHANGED
@@ -1,48 +1,16 @@
|
|
1
1
|
require 'rollbar'
|
2
|
-
begin
|
3
|
-
require 'rack/mock'
|
4
|
-
rescue LoadError
|
5
|
-
puts 'Cannot load rack/mock'
|
6
|
-
end
|
7
|
-
require 'logger'
|
8
2
|
|
9
|
-
# Module to inject into the Rails controllers or rack apps
|
10
3
|
module RollbarTest # :nodoc:
|
11
|
-
def test_rollbar
|
12
|
-
puts 'Raising RollbarTestingException to simulate app failure.'
|
13
|
-
|
14
|
-
raise RollbarTestingException.new, ::RollbarTest.success_message
|
15
|
-
end
|
16
|
-
|
17
4
|
def self.run
|
18
5
|
return unless confirmed_token?
|
19
6
|
|
20
|
-
|
21
|
-
|
22
|
-
puts 'Testing manual report...'
|
23
|
-
Rollbar.error('Test error from rollbar:test')
|
24
|
-
|
25
|
-
return unless defined?(Rack::MockRequest)
|
26
|
-
|
27
|
-
protocol, app = setup_app
|
28
|
-
|
29
|
-
puts 'Processing...'
|
30
|
-
env = Rack::MockRequest.env_for("#{protocol}://www.example.com/verify", 'REMOTE_ADDR' => '127.0.0.1')
|
31
|
-
status, = app.call(env)
|
32
|
-
|
33
|
-
puts error_message unless status.to_i == 500
|
34
|
-
end
|
35
|
-
|
36
|
-
def self.configure_rails
|
37
|
-
Rails.logger = if defined?(ActiveSupport::TaggedLogging)
|
38
|
-
ActiveSupport::TaggedLogging.new(Logger.new(STDOUT))
|
39
|
-
else
|
40
|
-
Logger.new(STDOUT)
|
41
|
-
end
|
7
|
+
puts 'Test sending to Rollbar...'
|
8
|
+
result = Rollbar.info('Test message from rollbar:test')
|
42
9
|
|
43
|
-
|
44
|
-
|
45
|
-
|
10
|
+
if result == 'error'
|
11
|
+
puts error_message
|
12
|
+
else
|
13
|
+
puts success_message
|
46
14
|
end
|
47
15
|
end
|
48
16
|
|
@@ -54,94 +22,17 @@ module RollbarTest # :nodoc:
|
|
54
22
|
false
|
55
23
|
end
|
56
24
|
|
57
|
-
def self.authlogic_config
|
58
|
-
# from http://stackoverflow.com/questions/5270835/authlogic-activation-problems
|
59
|
-
return unless defined?(Authlogic)
|
60
|
-
|
61
|
-
Authlogic::Session::Base.controller = Authlogic::ControllerAdapters::RailsAdapter.new(self)
|
62
|
-
end
|
63
|
-
|
64
|
-
def self.setup_app
|
65
|
-
puts 'Setting up the test app.'
|
66
|
-
|
67
|
-
if defined?(Rails)
|
68
|
-
app = rails_app
|
69
|
-
|
70
|
-
draw_rails_route(app)
|
71
|
-
|
72
|
-
authlogic_config
|
73
|
-
|
74
|
-
[rails_protocol(app), app]
|
75
|
-
else
|
76
|
-
['http', rack_app]
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def self.rails_app
|
81
|
-
# The setup below is needed for Rails 5.x, but not for Rails 4.x and below.
|
82
|
-
# (And fails on Rails 4.x in various ways depending on the exact version.)
|
83
|
-
return Rails.application if Rails.version < '5.0.0'
|
84
|
-
|
85
|
-
# Spring now runs by default in development on all new Rails installs. This causes
|
86
|
-
# the new `/verify` route to not get picked up if `config.cache_classes == false`
|
87
|
-
# which is also a default in development env.
|
88
|
-
#
|
89
|
-
# `config.cache_classes` needs to be set, but the only possible time is at app load,
|
90
|
-
# so here we clone the default app with an updated config.
|
91
|
-
#
|
92
|
-
config = Rails.application.config
|
93
|
-
config.cache_classes = true
|
94
|
-
|
95
|
-
# Make a copy of the app, so the config can be updated.
|
96
|
-
Rails.application.class.name.constantize.new(:config => config)
|
97
|
-
end
|
98
|
-
|
99
|
-
def self.draw_rails_route(app)
|
100
|
-
app.routes_reloader.execute_if_updated
|
101
|
-
app.routes.draw do
|
102
|
-
get 'verify' => 'rollbar_test#verify', :as => 'verify'
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
def self.rails_protocol(app)
|
107
|
-
defined?(app.config.force_ssl && app.config.force_ssl) ? 'https' : 'http'
|
108
|
-
end
|
109
|
-
|
110
|
-
def self.rack_app
|
111
|
-
Class.new do
|
112
|
-
include RollbarTest
|
113
|
-
|
114
|
-
def self.call(_env)
|
115
|
-
new.test_rollbar
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
25
|
def self.token_error_message
|
121
26
|
'Rollbar needs an access token configured. Check the README for instructions.'
|
122
27
|
end
|
123
28
|
|
124
29
|
def self.error_message
|
125
|
-
'Test failed! You may have a configuration issue, or you could be using a
|
30
|
+
'Test failed! You may have a configuration issue, or you could be using a ' \
|
31
|
+
'gem that\'s blocking the test. Contact support@rollbar.com if you need ' \
|
32
|
+
'help troubleshooting.'
|
126
33
|
end
|
127
34
|
|
128
35
|
def self.success_message
|
129
36
|
'Testing rollbar with "rake rollbar:test". If you can see this, it works.'
|
130
37
|
end
|
131
38
|
end
|
132
|
-
|
133
|
-
class RollbarTestingException < RuntimeError; end
|
134
|
-
|
135
|
-
if defined?(Rails)
|
136
|
-
class RollbarTestController < ActionController::Base # :nodoc:
|
137
|
-
include RollbarTest
|
138
|
-
|
139
|
-
def verify
|
140
|
-
test_rollbar
|
141
|
-
end
|
142
|
-
|
143
|
-
def logger
|
144
|
-
nil
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end
|