rollbar 2.10.0 → 2.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +7 -2
  3. data/CHANGELOG.md +20 -0
  4. data/README.md +73 -16
  5. data/docs/configuration.md +10 -0
  6. data/gemfiles/rails30.gemfile +2 -0
  7. data/gemfiles/rails31.gemfile +2 -0
  8. data/gemfiles/rails32.gemfile +2 -0
  9. data/gemfiles/rails40.gemfile +2 -0
  10. data/gemfiles/rails41.gemfile +2 -0
  11. data/gemfiles/rails42.gemfile +2 -0
  12. data/gemfiles/rails50.gemfile +2 -0
  13. data/gemfiles/ruby_1_8_and_1_9_2.gemfile +43 -0
  14. data/lib/rollbar.rb +139 -353
  15. data/lib/rollbar/configuration.rb +4 -0
  16. data/lib/rollbar/item.rb +225 -0
  17. data/lib/rollbar/item/backtrace.rb +97 -0
  18. data/lib/rollbar/js.rb +0 -28
  19. data/lib/rollbar/language_support.rb +10 -0
  20. data/lib/rollbar/{js/middleware.rb → middleware/js.rb} +3 -4
  21. data/lib/rollbar/plugin.rb +63 -0
  22. data/lib/rollbar/plugins.rb +41 -0
  23. data/lib/rollbar/{active_job.rb → plugins/active_job.rb} +0 -0
  24. data/lib/rollbar/plugins/basic_socket.rb +16 -0
  25. data/lib/rollbar/plugins/delayed_job.rb +12 -0
  26. data/lib/rollbar/plugins/delayed_job/job_data.rb +16 -0
  27. data/lib/rollbar/{delayed_job.rb → plugins/delayed_job/plugin.rb} +1 -17
  28. data/lib/rollbar/plugins/goalie.rb +46 -0
  29. data/lib/rollbar/plugins/rack.rb +16 -0
  30. data/lib/rollbar/plugins/rails.rb +77 -0
  31. data/lib/rollbar/{rails → plugins/rails}/controller_methods.rb +0 -0
  32. data/lib/rollbar/plugins/rails/railtie30.rb +17 -0
  33. data/lib/rollbar/plugins/rails/railtie32.rb +18 -0
  34. data/lib/rollbar/plugins/rails/railtie_mixin.rb +33 -0
  35. data/lib/rollbar/plugins/rake.rb +45 -0
  36. data/lib/rollbar/plugins/sidekiq.rb +35 -0
  37. data/lib/rollbar/{sidekiq.rb → plugins/sidekiq/plugin.rb} +0 -18
  38. data/lib/rollbar/plugins/thread.rb +13 -0
  39. data/lib/rollbar/plugins/validations.rb +33 -0
  40. data/lib/rollbar/request_data_extractor.rb +30 -18
  41. data/lib/rollbar/scrubbers/params.rb +4 -2
  42. data/lib/rollbar/scrubbers/url.rb +30 -28
  43. data/lib/rollbar/util.rb +10 -0
  44. data/lib/rollbar/version.rb +1 -1
  45. data/spec/controllers/home_controller_spec.rb +4 -3
  46. data/spec/dummyapp/app/models/post.rb +9 -0
  47. data/spec/dummyapp/app/models/user.rb +2 -0
  48. data/spec/dummyapp/config/initializers/rollbar.rb +1 -0
  49. data/spec/fixtures/plugins/dummy1.rb +5 -0
  50. data/spec/fixtures/plugins/dummy2.rb +5 -0
  51. data/spec/rollbar/item_spec.rb +635 -0
  52. data/spec/rollbar/logger_proxy_spec.rb +4 -0
  53. data/spec/rollbar/{js/middleware_spec.rb → middleware/js_spec.rb} +32 -3
  54. data/spec/rollbar/plugin_spec.rb +147 -0
  55. data/spec/rollbar/{active_job_spec.rb → plugins/active_job_spec.rb} +0 -1
  56. data/spec/rollbar/{delayed_job → plugins/delayed_job}/job_data.rb +0 -0
  57. data/spec/rollbar/{delayed_job_spec.rb → plugins/delayed_job_spec.rb} +3 -6
  58. data/spec/rollbar/{middleware/rack/builder_spec.rb → plugins/rack_spec.rb} +2 -1
  59. data/spec/rollbar/{js/frameworks/rails_spec.rb → plugins/rails_js_spec.rb} +1 -1
  60. data/spec/rollbar/{rake_spec.rb → plugins/rake_spec.rb} +2 -1
  61. data/spec/rollbar/{sidekiq_spec.rb → plugins/sidekiq_spec.rb} +2 -1
  62. data/spec/rollbar/plugins/validations_spec.rb +43 -0
  63. data/spec/rollbar/plugins_spec.rb +68 -0
  64. data/spec/rollbar/request_data_extractor_spec.rb +56 -10
  65. data/spec/rollbar/scrubbers/params_spec.rb +13 -10
  66. data/spec/rollbar/scrubbers/url_spec.rb +17 -12
  67. data/spec/rollbar/sidekig/clear_scope_spec.rb +2 -1
  68. data/spec/rollbar/util_spec.rb +61 -0
  69. data/spec/rollbar_bc_spec.rb +10 -10
  70. data/spec/rollbar_spec.rb +57 -706
  71. data/spec/spec_helper.rb +8 -0
  72. data/spec/support/notifier_helpers.rb +1 -0
  73. data/spec/support/rollbar_api.rb +57 -0
  74. metadata +57 -33
  75. data/lib/rollbar/active_record_extension.rb +0 -14
  76. data/lib/rollbar/core_ext/basic_socket.rb +0 -7
  77. data/lib/rollbar/core_ext/thread.rb +0 -9
  78. data/lib/rollbar/goalie.rb +0 -33
  79. data/lib/rollbar/js/frameworks.rb +0 -6
  80. data/lib/rollbar/js/frameworks/rails.rb +0 -49
  81. data/lib/rollbar/js/version.rb +0 -5
  82. data/lib/rollbar/rack.rb +0 -9
  83. data/lib/rollbar/railtie.rb +0 -46
  84. data/lib/rollbar/rake.rb +0 -40
@@ -0,0 +1,41 @@
1
+ require 'rollbar/plugin'
2
+
3
+ module Rollbar
4
+ # Stores the available plugin definitions and loads them
5
+ class Plugins
6
+ attr_reader :collection
7
+
8
+ def initialize
9
+ @collection = []
10
+ end
11
+
12
+ def require_all
13
+ Dir.glob(plugin_files).each do |file|
14
+ require file.to_s
15
+ end
16
+ end
17
+
18
+ def plugin_files
19
+ File.expand_path('../plugins/*.rb', __FILE__)
20
+ end
21
+
22
+ def define(name, &block)
23
+ return if loaded?(name)
24
+
25
+ plugin = Rollbar::Plugin.new(name)
26
+ collection << plugin
27
+
28
+ plugin.instance_eval(&block)
29
+ end
30
+
31
+ def load!
32
+ collection.each(&:load!)
33
+ end
34
+
35
+ private
36
+
37
+ def loaded?(name)
38
+ collection.any? { |plugin| plugin.name == name }
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,16 @@
1
+ Rollbar.plugins.define('basic_socket') do
2
+ dependency { !configuration.disable_core_monkey_patch }
3
+
4
+ # Needed to avoid active_support (< 4.1.0) bug serializing JSONs
5
+ dependency { defined?(ActiveSupport::VERSION::STRING) }
6
+
7
+ execute do
8
+ require 'socket'
9
+
10
+ class BasicSocket
11
+ def as_json(*)
12
+ to_s
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,12 @@
1
+ Rollbar.plugins.define('delayed_job') do
2
+ dependency { !configuration.disable_monkey_patch }
3
+ dependency do
4
+ defined?(Delayed) && defined?(Delayed::Worker) && configuration.delayed_job_enabled
5
+ end
6
+
7
+ execute do
8
+ require 'rollbar/plugins/delayed_job/plugin'
9
+
10
+ Rollbar::Delayed.wrap_worker
11
+ end
12
+ end
@@ -0,0 +1,16 @@
1
+ class JobData
2
+ attr_reader :job
3
+
4
+ def initialize(job)
5
+ @job = job
6
+ end
7
+
8
+ def to_hash
9
+ job_data = job.as_json
10
+ # Here job_data['handler'] is a YAML object comming
11
+ # from the storage backend
12
+ job_data['handler'] = job.payload_object.as_json
13
+
14
+ job_data
15
+ end
16
+ end
@@ -1,4 +1,5 @@
1
1
  require 'delayed_job'
2
+ require 'rollbar/plugins/delayed_job/job_data'
2
3
 
3
4
  module Rollbar
4
5
  module Delayed
@@ -6,23 +7,6 @@ module Rollbar
6
7
  attr_accessor :wrapped
7
8
  end
8
9
 
9
- class JobData
10
- attr_reader :job
11
-
12
- def initialize(job)
13
- @job = job
14
- end
15
-
16
- def to_hash
17
- job_data = job.as_json
18
- # Here job_data['handler'] is a YAML object comming
19
- # from the storage backend
20
- job_data['handler'] = job.payload_object.as_json
21
-
22
- job_data
23
- end
24
- end
25
-
26
10
  class RollbarPlugin < ::Delayed::Plugin
27
11
  callbacks do |lifecycle|
28
12
  lifecycle.around(:invoke_job, &Delayed::invoke_job_callback)
@@ -0,0 +1,46 @@
1
+ Rollbar.plugins.define('goalie') do
2
+ dependency { !configuration.disable_monkey_patch }
3
+ dependency { defined?(Goalie) }
4
+
5
+ execute do
6
+ module Rollbar
7
+ module Goalie
8
+ def render_exception_with_rollbar(env, exception)
9
+ exception_data = nil
10
+
11
+ begin
12
+ controller = env['action_controller.instance']
13
+ request_data = controller.rollbar_request_data rescue nil
14
+ person_data = controller.rollbar_person_data rescue nil
15
+ exception_data = Rollbar.scope(:request => request_data, :person => person_data).error(exception, :use_exception_level_filters => true)
16
+ rescue => e
17
+ Rollbar.log_warning "[Rollbar] Exception while reporting exception to Rollbar: #{e}"
18
+ end
19
+
20
+ # if an exception was reported, save uuid in the env
21
+ # so it can be displayed to the user on the error page
22
+ if exception_data.is_a?(Hash)
23
+ env['rollbar.exception_uuid'] = exception_data[:uuid]
24
+ Rollbar.log_info "[Rollbar] Exception uuid saved in env: #{exception_data[:uuid]}"
25
+ elsif exception_data == 'disabled'
26
+ Rollbar.log_info "[Rollbar] Exception not reported because Rollbar is disabled"
27
+ elsif exception_data == 'ignored'
28
+ Rollbar.log_info "[Rollbar] Exception not reported because it was ignored"
29
+ end
30
+
31
+ # now continue as normal
32
+ render_exception_without_rollbar(env, exception)
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ execute do
39
+ Goalie::CustomErrorPages.class_eval do
40
+ include Rollbar::Goalie
41
+
42
+ alias_method :render_exception_without_rollbar, :render_exception
43
+ alias_method :render_exception, :render_exception_with_rollbar
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,16 @@
1
+ Rollbar.plugins.define('rack') do
2
+ dependency { !configuration.disable_monkey_patch }
3
+ dependency { !configuration.disable_rack_monkey_patch }
4
+
5
+ execute do
6
+ if defined?(Rack::Builder)
7
+ require 'rollbar/middleware/rack/builder'
8
+ Rack::Builder.send(:include, Rollbar::Middleware::Rack::Builder)
9
+ end
10
+
11
+ if defined?(Rack::Test::Session)
12
+ require 'rollbar/middleware/rack/test_session'
13
+ Rack::Test::Session.send(:include, Rollbar::Middleware::Rack::TestSession)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,77 @@
1
+ Rollbar.plugins.define('rails32-errors') do
2
+ dependency { defined?(Rails::VERSION) && Rails::VERSION::MAJOR >= 3 }
3
+ dependency { Gem::Version.new(Rails::VERSION::STRING) >= Gem::Version.new('3.2') }
4
+
5
+ execute! do
6
+ require 'rollbar/plugins/rails/railtie32'
7
+ end
8
+ end
9
+
10
+ Rollbar.plugins.define('rails30-errors') do
11
+ dependency { defined?(Rails::VERSION) && Rails::VERSION::MAJOR >= 3 }
12
+ dependency { Gem::Version.new(Rails::VERSION::STRING) < Gem::Version.new('3.2') }
13
+
14
+ execute! do
15
+ require 'rollbar/plugins/rails/railtie30'
16
+ end
17
+ end
18
+
19
+ Rollbar.plugins.define('rails-rollbar.js') do
20
+ dependency { defined?(Rails::VERSION) && Rails::VERSION::MAJOR >= 3 }
21
+
22
+ execute! do
23
+ module Rollbar
24
+ module Js
25
+ module Frameworks
26
+ # Adds Rollbar::Middleware::Js to the Rails middleware stack
27
+ # We need to delay the final insert to the last moment since
28
+ # this feature may be disable.
29
+ # But we need to prepare the middleware insert now because
30
+ # we need to use our Rails railtie initializer in case the
31
+ # customer is using SecureHeaders > 3.0
32
+ class Rails
33
+ def load(plugin)
34
+ plugin_execute = plugin_execute_proc(plugin)
35
+
36
+ return after_secure_headers(&plugin_execute) if secure_headers_middleware?
37
+
38
+ plugin_execute.call
39
+ end
40
+
41
+ def after_secure_headers(&block)
42
+ Rollbar::Railtie.initializer('rollbar.js.frameworks.rails', :after => 'secure_headers.middleware', &block)
43
+ end
44
+
45
+ def plugin_execute_proc(plugin)
46
+ proc do
47
+ plugin.execute do
48
+ return unless Rollbar.configuration.js_enabled
49
+ require 'rollbar/middleware/js'
50
+
51
+ config = {
52
+ :options => Rollbar.configuration.js_options,
53
+ :enabled => Rollbar.configuration.js_enabled
54
+ }
55
+ ::Rails.configuration.middleware.use(::Rollbar::Middleware::Js, config)
56
+ end
57
+ end
58
+ end
59
+
60
+ def secure_headers_middleware?
61
+ begin
62
+ require 'secure_headers'
63
+ rescue LoadError
64
+ end
65
+
66
+ defined?(::SecureHeaders::Middleware)
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
73
+
74
+ execute! do
75
+ Rollbar::Js::Frameworks::Rails.new.load(self)
76
+ end
77
+ end
@@ -0,0 +1,17 @@
1
+ require 'rails/railtie'
2
+ require 'rollbar/plugins/rails/railtie_mixin'
3
+
4
+ module Rollbar
5
+ class Railtie < ::Rails::Railtie
6
+ include Rollbar::RailtieMixin
7
+
8
+ initializer 'rollbar.middleware.rails' do |app|
9
+ require 'rollbar/middleware/rails/rollbar'
10
+ require 'rollbar/middleware/rails/show_exceptions'
11
+
12
+ app.config.middleware.insert_after ActionDispatch::ShowExceptions,
13
+ Rollbar::Middleware::Rails::RollbarMiddleware
14
+ ActionDispatch::ShowExceptions.send(:include, Rollbar::Middleware::Rails::ShowExceptions)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,18 @@
1
+ require 'rails/railtie'
2
+ require 'rollbar/plugins/rails/railtie_mixin'
3
+
4
+ module Rollbar
5
+ class Railtie < ::Rails::Railtie
6
+ include Rollbar::RailtieMixin
7
+
8
+ initializer 'rollbar.middleware.rails' do |app|
9
+ require 'rollbar/middleware/rails/rollbar'
10
+ require 'rollbar/middleware/rails/show_exceptions'
11
+
12
+ app.config.middleware.insert_after ActionDispatch::DebugExceptions,
13
+ Rollbar::Middleware::Rails::RollbarMiddleware
14
+ ActionDispatch::DebugExceptions.send(:include, Rollbar::Middleware::Rails::ShowExceptions)
15
+ end
16
+ end
17
+ end
18
+
@@ -0,0 +1,33 @@
1
+ require 'rollbar'
2
+
3
+ module Rollbar
4
+ module RailtieMixin
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ rake_tasks do
9
+ require 'rollbar/rake_tasks'
10
+ end
11
+
12
+ initializer 'rollbar.configuration' do
13
+ config.after_initialize do
14
+ Rollbar.preconfigure do |config|
15
+ config.default_logger = proc { ::Rails.logger }
16
+ config.environment ||= ::Rails.env
17
+ config.root ||= ::Rails.root
18
+ config.framework = "Rails: #{::Rails::VERSION::STRING}"
19
+ config.filepath ||= ::Rails.application.class.parent_name + '.rollbar'
20
+ end
21
+ end
22
+ end
23
+
24
+ initializer 'rollbar.controller_methods' do
25
+ ActiveSupport.on_load(:action_controller) do
26
+ # lazily load action_controller methods
27
+ require 'rollbar/plugins/rails/controller_methods'
28
+ include Rollbar::Rails::ControllerMethods
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,45 @@
1
+ Rollbar.plugins.define('rake') do
2
+ dependency { !configuration.disable_monkey_patch }
3
+ dependency { defined?(Rake) }
4
+
5
+ module Rollbar
6
+ module Rake
7
+ def self.patch!
8
+ skip_patch && return unless patch?
9
+
10
+ ::Rake::Application.class_eval do
11
+ alias_method :orig_display_error_message, :display_error_message
12
+
13
+ def display_error_message(ex)
14
+ Rollbar.error(ex, :use_exception_level_filters => true)
15
+ orig_display_error_message(ex)
16
+ end
17
+ end
18
+ end
19
+
20
+ def self.skip_patch
21
+ warn('[Rollbar] Rollbar is disabled for Rake tasks since your Rake version is under 0.9.x. Please upgrade to 0.9.x or higher.')
22
+ end
23
+
24
+ def self.patch?
25
+ return false unless rake_version
26
+
27
+ major, minor, = rake_version.split('.').map(&:to_i)
28
+
29
+ major > 0 || major == 0 && minor > 8
30
+ end
31
+
32
+ def self.rake_version
33
+ if Object.const_defined?('RAKEVERSION')
34
+ return RAKEVERSION
35
+ elsif ::Rake.const_defined?('VERSION')
36
+ return ::Rake::VERSION
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ execute do
43
+ Rollbar::Rake.patch!
44
+ end
45
+ end
@@ -0,0 +1,35 @@
1
+ Rollbar.plugins.define('sidekiq >= 3') do
2
+ dependency { !configuration.disable_monkey_patch }
3
+ dependency { defined?(Sidekiq) }
4
+ dependency { Sidekiq::VERSION.split('.')[0].to_i >= 3 }
5
+
6
+ execute do
7
+ require 'rollbar/plugins/sidekiq/plugin'
8
+
9
+ Sidekiq.configure_server do |config|
10
+ config.server_middleware do |chain|
11
+ chain.add Rollbar::Sidekiq::ClearScope
12
+ end
13
+
14
+ config.error_handlers << proc do |e, context|
15
+ Rollbar::Sidekiq.handle_exception(context, e)
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+ Rollbar.plugins.define('sidekiq < 3') do
22
+ dependency { !configuration.disable_monkey_patch }
23
+ dependency { defined?(Sidekiq) }
24
+ dependency { Sidekiq::VERSION.split('.')[0].to_i < 3 }
25
+
26
+ execute do
27
+ require 'rollbar/plugins/sidekiq/plugin'
28
+
29
+ Sidekiq.configure_server do |config|
30
+ config.server_middleware do |chain|
31
+ chain.add Rollbar::Sidekiq
32
+ end
33
+ end
34
+ end
35
+ end
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Rollbar
4
2
  class Sidekiq
5
3
  PARAM_BLACKLIST = %w[backtrace error_backtrace error_message error_class]
@@ -43,19 +41,3 @@ module Rollbar
43
41
  end
44
42
  end
45
43
  end
46
-
47
- Sidekiq.configure_server do |config|
48
- if Sidekiq::VERSION.split('.')[0].to_i < 3
49
- config.server_middleware do |chain|
50
- chain.add Rollbar::Sidekiq
51
- end
52
- else
53
- config.server_middleware do |chain|
54
- chain.add Rollbar::Sidekiq::ClearScope
55
- end
56
-
57
- config.error_handlers << proc do |e, context|
58
- Rollbar::Sidekiq.handle_exception(context, e)
59
- end
60
- end
61
- end