rollbar 2.23.2 → 3.3.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.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/.github/pull_request_template.md +25 -0
  3. data/.github/workflows/ci.yml +118 -0
  4. data/.rubocop.yml +85 -34
  5. data/Gemfile +22 -22
  6. data/README.md +11 -9
  7. data/data/rollbar.snippet.js +1 -1
  8. data/docs/configuration.md +8 -0
  9. data/gemfiles/rails30.gemfile +18 -35
  10. data/gemfiles/rails31.gemfile +21 -37
  11. data/gemfiles/rails32.gemfile +14 -31
  12. data/gemfiles/rails40.gemfile +13 -32
  13. data/gemfiles/rails41.gemfile +12 -31
  14. data/gemfiles/rails42.gemfile +12 -35
  15. data/gemfiles/rails50.gemfile +17 -29
  16. data/gemfiles/rails51.gemfile +17 -29
  17. data/gemfiles/rails52.gemfile +7 -14
  18. data/gemfiles/rails60.gemfile +7 -20
  19. data/gemfiles/rails61.gemfile +54 -0
  20. data/lib/generators/rollbar/rollbar_generator.rb +18 -14
  21. data/lib/generators/rollbar/templates/{initializer.rb → initializer.erb} +0 -0
  22. data/lib/rails/rollbar_runner.rb +15 -6
  23. data/lib/rollbar/capistrano.rb +17 -9
  24. data/lib/rollbar/capistrano3.rb +8 -2
  25. data/lib/rollbar/capistrano_tasks.rb +44 -8
  26. data/lib/rollbar/configuration.rb +128 -84
  27. data/lib/rollbar/delay/shoryuken.rb +4 -3
  28. data/lib/rollbar/delay/sidekiq.rb +3 -1
  29. data/lib/rollbar/delay/sucker_punch.rb +1 -2
  30. data/lib/rollbar/delay/thread.rb +3 -2
  31. data/lib/rollbar/deploy.rb +8 -7
  32. data/lib/rollbar/encoding/encoder.rb +10 -3
  33. data/lib/rollbar/exception_reporter.rb +17 -8
  34. data/lib/rollbar/item/backtrace.rb +11 -9
  35. data/lib/rollbar/item/frame.rb +6 -5
  36. data/lib/rollbar/item/locals.rb +3 -2
  37. data/lib/rollbar/item.rb +68 -40
  38. data/lib/rollbar/json.rb +2 -1
  39. data/lib/rollbar/language_support.rb +0 -6
  40. data/lib/rollbar/lazy_store.rb +3 -7
  41. data/lib/rollbar/logger.rb +2 -0
  42. data/lib/rollbar/logger_proxy.rb +3 -1
  43. data/lib/rollbar/middleware/js.rb +64 -37
  44. data/lib/rollbar/middleware/rack/builder.rb +3 -3
  45. data/lib/rollbar/middleware/rack/test_session.rb +3 -3
  46. data/lib/rollbar/middleware/rack.rb +4 -4
  47. data/lib/rollbar/middleware/rails/rollbar.rb +9 -6
  48. data/lib/rollbar/middleware/rails/show_exceptions.rb +8 -4
  49. data/lib/rollbar/notifier/trace_with_bindings.rb +4 -2
  50. data/lib/rollbar/notifier.rb +272 -159
  51. data/lib/rollbar/plugin.rb +8 -8
  52. data/lib/rollbar/plugins/active_job.rb +11 -2
  53. data/lib/rollbar/plugins/delayed_job/plugin.rb +19 -2
  54. data/lib/rollbar/plugins/goalie.rb +27 -16
  55. data/lib/rollbar/plugins/rails/controller_methods.rb +18 -14
  56. data/lib/rollbar/plugins/rails/railtie30.rb +2 -1
  57. data/lib/rollbar/plugins/rails/railtie32.rb +2 -1
  58. data/lib/rollbar/plugins/rails/railtie_mixin.rb +2 -2
  59. data/lib/rollbar/plugins/rails.rb +5 -2
  60. data/lib/rollbar/plugins/rake.rb +2 -1
  61. data/lib/rollbar/plugins/sidekiq/plugin.rb +37 -20
  62. data/lib/rollbar/plugins/sidekiq.rb +1 -1
  63. data/lib/rollbar/plugins/thread.rb +8 -7
  64. data/lib/rollbar/plugins/validations.rb +3 -1
  65. data/lib/rollbar/rake_tasks.rb +1 -2
  66. data/lib/rollbar/request_data_extractor.rb +43 -16
  67. data/lib/rollbar/rollbar_test.rb +9 -118
  68. data/lib/rollbar/scrubbers/params.rb +13 -7
  69. data/lib/rollbar/scrubbers/url.rb +56 -17
  70. data/lib/rollbar/scrubbers.rb +1 -1
  71. data/lib/rollbar/truncation/remove_any_key_strategy.rb +4 -1
  72. data/lib/rollbar/truncation/remove_extra_strategy.rb +3 -1
  73. data/lib/rollbar/util/hash.rb +14 -7
  74. data/lib/rollbar/util/ip_anonymizer.rb +1 -1
  75. data/lib/rollbar/util.rb +19 -13
  76. data/lib/rollbar/version.rb +1 -1
  77. data/lib/rollbar.rb +12 -7
  78. data/lib/tasks/benchmark.rake +2 -1
  79. data/rollbar.gemspec +5 -2
  80. data/spec/support/rollbar_api.rb +67 -0
  81. metadata +9 -6
  82. data/.travis.yml +0 -284
@@ -0,0 +1,54 @@
1
+ require 'rubygems/version'
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ is_jruby = defined?(JRUBY_VERSION) || (defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby')
6
+
7
+ gem 'activerecord-jdbcsqlite3-adapter', :platform => :jruby
8
+ gem 'jruby-openssl', :platform => :jruby
9
+ gem 'rails', '~> 6.1.3'
10
+ gem 'sqlite3', '~> 1.4', :platform => [:ruby, :mswin, :mingw]
11
+
12
+ gem 'rspec-rails', '~> 4.0.2'
13
+
14
+ gem 'rake'
15
+
16
+ gem 'sidekiq', '>= 2.13.0'
17
+
18
+ platforms :rbx do
19
+ gem 'minitest'
20
+ gem 'racc'
21
+ gem 'rubinius-developer_tools'
22
+ gem 'rubysl', '~> 2.0' if RUBY_VERSION.start_with?('2')
23
+ end
24
+
25
+ gem 'sucker_punch', '~> 2.0'
26
+
27
+ # We need last sinatra that uses rack 2.x
28
+ gem 'sinatra', :git => 'https://github.com/sinatra/sinatra'
29
+
30
+ gem 'codacy-coverage'
31
+ gem 'database_cleaner'
32
+ gem 'delayed_job', '4.1.9', :require => false
33
+ gem 'generator_spec'
34
+ gem 'girl_friday', '>= 0.11.1'
35
+ gem 'redis'
36
+ gem 'resque'
37
+ gem 'secure_headers', '~> 6.3.2', :require => false
38
+ gem 'simplecov'
39
+
40
+ unless is_jruby
41
+ # JRuby doesn't support fork, which is required for this test helper.
42
+ gem 'rspec-command'
43
+ end
44
+
45
+ gem 'mime-types'
46
+
47
+ gem 'webmock', :require => false
48
+
49
+ gem 'aws-sdk-sqs'
50
+ gem 'shoryuken'
51
+
52
+ gem 'capistrano', :require => false
53
+
54
+ gemspec :path => '../'
@@ -5,7 +5,8 @@ require 'generators/rollbar/rollbar_generator'
5
5
  module Rollbar
6
6
  module Generators
7
7
  class RollbarGenerator < ::Rails::Generators::Base
8
- argument :access_token, :type => :string, :banner => 'access_token', :default => :use_env_sentinel
8
+ argument :access_token, :type => :string, :banner => 'access_token',
9
+ :default => :use_env_sentinel
9
10
 
10
11
  source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
11
12
 
@@ -13,32 +14,35 @@ module Rollbar
13
14
  say 'creating initializer...'
14
15
  if access_token_configured?
15
16
  say "It looks like you've already configured Rollbar."
16
- say 'To re-create the config file, remove it first: config/initializers/rollbar.rb'
17
+ say 'To re-create the config file, remove it first: ' \
18
+ 'config/initializers/rollbar.rb'
17
19
  exit
18
20
  end
19
21
 
20
22
  begin
21
23
  require 'ey_config'
22
24
  rescue LoadError
25
+ # Skip loading
23
26
  end
24
27
 
25
28
  if defined? EY::Config
26
29
  say 'Access token will be read from Engine Yard configuration'
30
+ elsif access_token === :use_env_sentinel
31
+ say 'Generator run without an access token; assuming you want to ' \
32
+ 'configure using an environment variable.'
33
+ say "You'll need to add an environment variable ROLLBAR_ACCESS_TOKEN " \
34
+ 'with your access token:'
35
+ say "\n$ export ROLLBAR_ACCESS_TOKEN=yourtokenhere"
36
+ say "\nIf that's not what you wanted to do:"
37
+ say "\n$ rm config/initializers/rollbar.rb"
38
+ say '$ rails generate rollbar yourtokenhere'
39
+ say "\n"
27
40
  else
28
- if access_token === :use_env_sentinel
29
- say 'Generator run without an access token; assuming you want to configure using an environment variable.'
30
- say "You'll need to add an environment variable ROLLBAR_ACCESS_TOKEN with your access token:"
31
- say "\n$ export ROLLBAR_ACCESS_TOKEN=yourtokenhere"
32
- say "\nIf that's not what you wanted to do:"
33
- say "\n$ rm config/initializers/rollbar.rb"
34
- say '$ rails generate rollbar yourtokenhere'
35
- say "\n"
36
- else
37
- say 'access token: ' << access_token
38
- end
41
+ say 'access token: ' << access_token
39
42
  end
40
43
 
41
- template 'initializer.rb', 'config/initializers/rollbar.rb', :assigns => { :access_token => access_token_expr }
44
+ template 'initializer.erb', 'config/initializers/rollbar.rb',
45
+ :assigns => { :access_token => access_token_expr }
42
46
 
43
47
  # TODO: run rake test task
44
48
  end
@@ -4,7 +4,10 @@ require 'rollbar'
4
4
  # Rails.root is not present here.
5
5
  # RSpec needs ENV['DUMMYAPP_PATH'] in order to have a valid path.
6
6
  # Dir.pwd is used in normal operation.
7
- APP_PATH = File.expand_path('config/application', (ENV['DUMMYAPP_PATH'] || Dir.pwd))
7
+ APP_PATH = File.expand_path(
8
+ 'config/application',
9
+ (ENV['DUMMYAPP_PATH'] || Dir.pwd)
10
+ )
8
11
 
9
12
  module Rails
10
13
  class RollbarRunner
@@ -39,7 +42,7 @@ module Rails
39
42
  end
40
43
 
41
44
  def eval_runner
42
- if Rails.version >= '5.1.0'
45
+ if Gem::Version.new(Rails.version) >= Gem::Version.new('5.1.0')
43
46
  rails5_runner
44
47
  else
45
48
  legacy_runner
@@ -49,12 +52,14 @@ module Rails
49
52
  def legacy_runner
50
53
  string_to_eval = File.read(runner_path)
51
54
 
52
- ::Rails.module_eval(<<-EOL, __FILE__, __LINE__ + 2)
55
+ ::Rails.module_eval(<<-FILE, __FILE__, __LINE__ + 1)
53
56
  #{string_to_eval}
54
- EOL
57
+ FILE
55
58
  end
56
59
 
57
60
  def rails5_runner
61
+ require 'rails/command'
62
+
58
63
  Rails::Command.invoke 'runner', ARGV
59
64
  end
60
65
 
@@ -66,11 +71,15 @@ module Rails
66
71
  end
67
72
 
68
73
  def runner_path
69
- railties_gem_dir + '/lib/rails/commands/runner.rb'
74
+ "#{railties_gem_dir}/lib/rails/commands/runner.rb"
70
75
  end
71
76
 
72
77
  def railties_gem
73
- resolver_class = Gem::Specification.respond_to?(:find_by_name) ? GemResolver : LegacyGemResolver
78
+ resolver_class = if Gem::Specification.respond_to?(:find_by_name)
79
+ GemResolver
80
+ else
81
+ LegacyGemResolver
82
+ end
74
83
  gem = resolver_class.new.railties_gem
75
84
 
76
85
  abort 'railties gem not found' unless gem
@@ -34,8 +34,12 @@ module Rollbar
34
34
  _cset(:rollbar_role) { :app }
35
35
  _cset(:rollbar_user) { ENV['USER'] || ENV['USERNAME'] }
36
36
  _cset(:rollbar_env) { fetch(:rails_env, 'production') }
37
- _cset(:rollbar_token) { abort("Please specify the Rollbar access token, set :rollbar_token, 'your token'") }
38
- _cset(:rollbar_revision) { current_revision }
37
+ _cset(:rollbar_token) do
38
+ abort(
39
+ "Please specify the Rollbar access token, set :rollbar_token, 'your token'"
40
+ )
41
+ end
42
+ _cset(:rollbar_revision) { real_revision }
39
43
  _cset(:rollbar_comment) { nil }
40
44
  end
41
45
  end
@@ -51,7 +55,9 @@ module Rollbar
51
55
  :task => :deploy_started,
52
56
  :configuration => configuration
53
57
  ) do
54
- ::Rollbar::CapistranoTasks.deploy_started(configuration, configuration.logger, configuration.dry_run)
58
+ ::Rollbar::CapistranoTasks.deploy_started(
59
+ configuration, configuration.logger, configuration.dry_run
60
+ )
55
61
  end
56
62
  end
57
63
 
@@ -61,17 +67,17 @@ module Rollbar
61
67
  :task => :deploy_succeeded,
62
68
  :configuration => configuration
63
69
  ) do
64
- ::Rollbar::CapistranoTasks.deploy_succeeded(configuration, configuration.logger, configuration.dry_run)
70
+ ::Rollbar::CapistranoTasks.deploy_succeeded(
71
+ configuration, configuration.logger, configuration.dry_run
72
+ )
65
73
  end
66
74
  end
67
75
 
68
- def load_task(configuration:, desc:, task:)
76
+ def load_task(configuration:, desc:, task:, &block)
69
77
  configuration.load do
70
78
  namespace :rollbar do
71
79
  desc(desc)
72
- task(task) do
73
- yield
74
- end
80
+ task(task, &block)
75
81
  end
76
82
  end
77
83
  end
@@ -79,4 +85,6 @@ module Rollbar
79
85
  end
80
86
  end
81
87
 
82
- Rollbar::Capistrano2.load_into(Capistrano::Configuration.instance) if Capistrano::Configuration.instance
88
+ if Capistrano::Configuration.instance
89
+ Rollbar::Capistrano2.load_into(Capistrano::Configuration.instance)
90
+ end
@@ -8,7 +8,10 @@ require 'rollbar/capistrano_tasks'
8
8
 
9
9
  namespace :rollbar do
10
10
  # dry_run? wasn't introduced till Capistrano 3.5.0; use the old fetch(:sshkit_backed)
11
- set :dry_run, (proc { ::Capistrano::Configuration.env.fetch(:sshkit_backend) == ::SSHKit::Backend::Printer })
11
+ set :dry_run, (proc {
12
+ ::Capistrano::Configuration.env.fetch(:sshkit_backend) ==
13
+ ::SSHKit::Backend::Printer
14
+ })
12
15
 
13
16
  desc 'Send deployment started notification to Rollbar.'
14
17
  task :deploy_started do
@@ -49,7 +52,10 @@ namespace :load do
49
52
  task :defaults do
50
53
  set :rollbar_user, (proc { fetch :local_user, ENV['USER'] || ENV['USERNAME'] })
51
54
  set :rollbar_env, (proc { fetch :rails_env, 'production' })
52
- set :rollbar_token, (proc { abort "Please specify the Rollbar access token, set :rollbar_token, 'your token'" })
55
+ set :rollbar_token, (proc {
56
+ abort 'Please specify the Rollbar access token, ' \
57
+ "set :rollbar_token, 'your token'"
58
+ })
53
59
  set :rollbar_role, (proc { :app })
54
60
  set :rollbar_revision, (proc { fetch :current_revision })
55
61
  end
@@ -13,23 +13,31 @@ module Rollbar
13
13
  capistrano.set(:rollbar_deploy_id, 123) if dry_run
14
14
 
15
15
  skip_in_dry_run(logger, dry_run) do
16
- if result[:success] && (deploy_id = result[:data] && result[:data][:deploy_id])
16
+ if result[:success] &&
17
+ (deploy_id = result[:data] &&
18
+ result[:data][:deploy_id])
17
19
  capistrano.set :rollbar_deploy_id, deploy_id
18
20
  else
19
- logger.error 'Unable to report deploy to Rollbar' + (result[:message] ? ': ' + result[:message] : '')
21
+ message = format_message('Unable to report deploy to Rollbar',
22
+ result[:message])
23
+ log_error(logger, message)
20
24
  end
21
25
  end
22
26
  end
23
27
  end
24
28
 
25
29
  def deploy_succeeded(capistrano, logger, dry_run)
26
- deploy_update(capistrano, logger, dry_run, :desc => 'Setting deployment status to `succeeded` in Rollbar') do
30
+ deploy_update(
31
+ capistrano, logger, dry_run,
32
+ :desc => 'Setting deployment status to `succeeded` in Rollbar'
33
+ ) do
27
34
  report_deploy_succeeded(capistrano, dry_run)
28
35
  end
29
36
  end
30
37
 
31
38
  def deploy_failed(capistrano, logger, dry_run)
32
- deploy_update(capistrano, logger, dry_run, :desc => 'Setting deployment status to `failed` in Rollbar') do
39
+ deploy_update(capistrano, logger, dry_run,
40
+ :desc => 'Setting deployment status to `failed` in Rollbar') do
33
41
  report_deploy_failed(capistrano, dry_run)
34
42
  end
35
43
  end
@@ -40,6 +48,8 @@ module Rollbar
40
48
  capistrano_300_warning(logger)
41
49
  logger.info opts[:desc] if opts[:desc]
42
50
  yield
51
+ rescue StandardError => e
52
+ log_error logger, "Error reporting to Rollbar: #{e.inspect}"
43
53
  end
44
54
 
45
55
  def deploy_update(capistrano, logger, dry_run, opts = {})
@@ -53,7 +63,9 @@ module Rollbar
53
63
  if result[:success]
54
64
  logger.info 'Updated deploy status in Rollbar'
55
65
  else
56
- logger.error 'Unable to update deploy status in Rollbar' + (result[:message] ? ': ' + result[:message] : '')
66
+ message = format_message('Unable to update deploy status in Rollbar',
67
+ result[:message])
68
+ log_error(logger, message)
57
69
  end
58
70
  end
59
71
  end
@@ -61,7 +73,13 @@ module Rollbar
61
73
  end
62
74
 
63
75
  def capistrano_300_warning(logger)
64
- logger.warn("You need to upgrade capistrano to '>= 3.1' version in order to correctly report deploys to Rollbar. (On 3.0, the reported revision will be incorrect.)") if ::Capistrano::VERSION =~ /^3\.0/
76
+ unless ::Capistrano.const_defined?('VERSION') && ::Capistrano::VERSION =~ /^3\.0/
77
+ return
78
+ end
79
+
80
+ logger.warn('You need to upgrade capistrano to >= 3.1 version in order'\
81
+ 'to correctly report deploys to Rollbar. (On 3.0, the reported revision'\
82
+ 'will be incorrect.)')
65
83
  end
66
84
 
67
85
  def report_deploy_started(capistrano, dry_run)
@@ -83,6 +101,7 @@ module Rollbar
83
101
  def report_deploy_succeeded(capistrano, dry_run)
84
102
  ::Rollbar::Deploy.update(
85
103
  {
104
+ :comment => capistrano.fetch(:rollbar_comment),
86
105
  :proxy => :ENV,
87
106
  :dry_run => dry_run
88
107
  },
@@ -95,6 +114,7 @@ module Rollbar
95
114
  def report_deploy_failed(capistrano, dry_run)
96
115
  ::Rollbar::Deploy.update(
97
116
  {
117
+ :comment => capistrano.fetch(:rollbar_comment),
98
118
  :proxy => :ENV,
99
119
  :dry_run => dry_run
100
120
  },
@@ -108,7 +128,8 @@ module Rollbar
108
128
  if capistrano.fetch(:rollbar_deploy_id)
109
129
  yield
110
130
  else
111
- logger.error 'Failed to update the deploy in Rollbar. No deploy id available.'
131
+ log_error logger,
132
+ 'Failed to update the deploy in Rollbar. No deploy id available.'
112
133
  end
113
134
  end
114
135
 
@@ -121,10 +142,25 @@ module Rollbar
121
142
  end
122
143
 
123
144
  def debug_request_response(logger, result)
124
- # NOTE: in Capistrano debug messages go to log/capistrano.log but not to stdout even if log_level == :debug
145
+ # NOTE: in Capistrano debug messages go to log/capistrano.log but not to
146
+ # stdout even if log_level == :debug
125
147
  logger.debug result[:request_info]
126
148
  logger.debug result[:response_info] if result[:response_info]
127
149
  end
150
+
151
+ def format_message(*args)
152
+ args.compact.join(': ')
153
+ end
154
+
155
+ def log_error(logger, message)
156
+ # Capistrano 2.x doesn't have the #error method,
157
+ # so we use #important if #error isn't present
158
+ if logger.respond_to?(:error)
159
+ logger.error message
160
+ elsif logger.respond_to?(:important)
161
+ logger.important message
162
+ end
163
+ end
128
164
  end
129
165
  end
130
166
  end