rollbar 2.22.1 → 3.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/.github/pull_request_template.md +34 -0
  3. data/.github/workflows/ci.yml +104 -0
  4. data/.rubocop.yml +185 -33
  5. data/Gemfile +26 -28
  6. data/README.md +32 -8
  7. data/data/rollbar.snippet.js +1 -1
  8. data/docs/configuration.md +8 -0
  9. data/gemfiles/rails30.gemfile +17 -35
  10. data/gemfiles/rails31.gemfile +20 -37
  11. data/gemfiles/rails32.gemfile +13 -31
  12. data/gemfiles/rails40.gemfile +12 -32
  13. data/gemfiles/rails41.gemfile +11 -31
  14. data/gemfiles/rails42.gemfile +12 -32
  15. data/gemfiles/rails50.gemfile +16 -30
  16. data/gemfiles/rails51.gemfile +16 -30
  17. data/gemfiles/rails52.gemfile +10 -19
  18. data/gemfiles/rails60.gemfile +10 -25
  19. data/gemfiles/rails61.gemfile +52 -0
  20. data/gemfiles/rails70.gemfile +52 -0
  21. data/lib/generators/rollbar/rollbar_generator.rb +18 -14
  22. data/lib/rails/rollbar_runner.rb +11 -20
  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 +138 -84
  27. data/lib/rollbar/delay/girl_friday.rb +3 -7
  28. data/lib/rollbar/delay/resque.rb +2 -3
  29. data/lib/rollbar/delay/shoryuken.rb +4 -3
  30. data/lib/rollbar/delay/sidekiq.rb +5 -5
  31. data/lib/rollbar/delay/sucker_punch.rb +4 -6
  32. data/lib/rollbar/delay/thread.rb +17 -2
  33. data/lib/rollbar/deploy.rb +8 -7
  34. data/lib/rollbar/encoding/encoder.rb +17 -6
  35. data/lib/rollbar/encoding.rb +2 -7
  36. data/lib/rollbar/exception_reporter.rb +17 -8
  37. data/lib/rollbar/item/backtrace.rb +22 -10
  38. data/lib/rollbar/item/frame.rb +8 -5
  39. data/lib/rollbar/item/locals.rb +49 -2
  40. data/lib/rollbar/item.rb +80 -50
  41. data/lib/rollbar/json.rb +2 -1
  42. data/lib/rollbar/language_support.rb +0 -6
  43. data/lib/rollbar/lazy_store.rb +3 -7
  44. data/lib/rollbar/logger.rb +2 -0
  45. data/lib/rollbar/logger_proxy.rb +3 -1
  46. data/lib/rollbar/middleware/js/json_value.rb +15 -5
  47. data/lib/rollbar/middleware/js.rb +70 -38
  48. data/lib/rollbar/middleware/rack/builder.rb +3 -3
  49. data/lib/rollbar/middleware/rack/test_session.rb +3 -3
  50. data/lib/rollbar/middleware/rack.rb +4 -4
  51. data/lib/rollbar/middleware/rails/rollbar.rb +9 -6
  52. data/lib/rollbar/middleware/rails/show_exceptions.rb +8 -4
  53. data/lib/rollbar/notifier/trace_with_bindings.rb +13 -3
  54. data/lib/rollbar/notifier.rb +309 -172
  55. data/lib/rollbar/plugin.rb +8 -8
  56. data/lib/rollbar/plugins/active_job.rb +20 -3
  57. data/lib/rollbar/plugins/delayed_job/plugin.rb +19 -2
  58. data/lib/rollbar/plugins/error_context.rb +11 -0
  59. data/lib/rollbar/plugins/goalie.rb +27 -16
  60. data/lib/rollbar/plugins/rails/controller_methods.rb +18 -14
  61. data/lib/rollbar/plugins/rails/railtie30.rb +2 -1
  62. data/lib/rollbar/plugins/rails/railtie32.rb +2 -1
  63. data/lib/rollbar/plugins/rails/railtie_mixin.rb +2 -2
  64. data/lib/rollbar/plugins/rails.rb +5 -2
  65. data/lib/rollbar/plugins/rake.rb +2 -1
  66. data/lib/rollbar/plugins/sidekiq/plugin.rb +39 -21
  67. data/lib/rollbar/plugins/sidekiq.rb +1 -1
  68. data/lib/rollbar/plugins/thread.rb +8 -7
  69. data/lib/rollbar/plugins/validations.rb +3 -1
  70. data/lib/rollbar/rake_tasks.rb +1 -2
  71. data/lib/rollbar/request_data_extractor.rb +53 -19
  72. data/lib/rollbar/rollbar_test.rb +9 -118
  73. data/lib/rollbar/scrubbers/params.rb +13 -7
  74. data/lib/rollbar/scrubbers/url.rb +56 -17
  75. data/lib/rollbar/scrubbers.rb +2 -6
  76. data/lib/rollbar/truncation/frames_strategy.rb +1 -1
  77. data/lib/rollbar/truncation/mixin.rb +1 -1
  78. data/lib/rollbar/truncation/remove_any_key_strategy.rb +4 -1
  79. data/lib/rollbar/truncation/remove_extra_strategy.rb +3 -1
  80. data/lib/rollbar/truncation/strings_strategy.rb +4 -2
  81. data/lib/rollbar/util/hash.rb +14 -7
  82. data/lib/rollbar/util/ip_anonymizer.rb +1 -1
  83. data/lib/rollbar/util.rb +23 -13
  84. data/lib/rollbar/version.rb +1 -1
  85. data/lib/rollbar.rb +12 -7
  86. data/lib/tasks/benchmark.rake +2 -1
  87. data/rollbar.gemspec +6 -3
  88. data/spec/support/rollbar_api.rb +67 -0
  89. metadata +19 -12
  90. data/.travis.yml +0 -281
  91. data/lib/rollbar/encoding/legacy_encoder.rb +0 -20
  92. /data/lib/generators/rollbar/templates/{initializer.rb → initializer.erb} +0 -0
@@ -1,53 +1,38 @@
1
-
2
1
  require 'rubygems/version'
3
2
 
4
3
  source 'https://rubygems.org'
5
4
 
6
- # Used by spec/commands/rollbar_rails_runner_spec, and can be used whenever a
7
- # new process is created during tests. (Testing rake tasks, for example.)
8
- # This is a workaround for ENV['BUNDLE_GEMFILE'] not working as expected on Travis.
9
- # We use the ||= assignment because Travis loads the gemfile twice, the second time
10
- # with the wrong gemfile path.
11
- ENV['CURRENT_GEMFILE'] ||= __FILE__
12
-
13
- is_jruby = defined?(JRUBY_VERSION) || (defined?(RUBY_ENGINE) && 'jruby' == RUBY_ENGINE)
5
+ is_jruby = defined?(JRUBY_VERSION) || (defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby')
14
6
 
15
- gem 'appraisal'
16
7
  gem 'activerecord-jdbcsqlite3-adapter', :platform => :jruby
17
8
  gem 'jruby-openssl', :platform => :jruby
18
- gem 'rails', '6.0.0.rc1'
9
+ gem 'rails', '~> 6.0.2'
19
10
  gem 'sqlite3', '~> 1.4', :platform => [:ruby, :mswin, :mingw]
20
11
 
21
- gem 'rspec-core', '~> 3.8.0'
22
- gem 'rspec-support', '~> 3.8.0'
23
- gem 'rspec-expectations', '~> 3.8.0'
24
- gem 'rspec-mocks', '~> 3.8.0'
25
- # TODO: update this when 4.x becomes available on Rubygems
26
- gem 'rspec-rails', :git => 'https://github.com/rspec/rspec-rails', :ref => 'v4.0.0.beta2' # rubocop:disable Bundler/DuplicatedGem
12
+ gem 'rspec-rails', '~> 4.0.2'
27
13
 
28
14
  gem 'rake'
29
15
 
30
- gem 'sidekiq', '>= 2.13.0'
16
+ gem 'sidekiq', '>= 6.4.0'
31
17
 
32
18
  platforms :rbx do
33
19
  gem 'minitest'
34
20
  gem 'racc'
35
21
  gem 'rubinius-developer_tools'
36
- gem 'rubysl', '~> 2.0' unless RUBY_VERSION.start_with?('1')
22
+ gem 'rubysl', '~> 2.0' if RUBY_VERSION.start_with?('2')
37
23
  end
38
24
 
39
25
  gem 'sucker_punch', '~> 2.0'
40
26
 
41
- # We need last sinatra that uses rack 2.x
42
- gem 'sinatra', :git => 'https://github.com/sinatra/sinatra'
27
+ # We need last sinatra that uses rack 2.x and ruby 2.5.x
28
+ gem 'sinatra', :git => 'https://github.com/sinatra/sinatra', :tag =>'v2.1.0'
43
29
 
44
30
  gem 'database_cleaner'
45
- gem 'codacy-coverage'
46
- gem 'delayed_job', '4.1.8.beta1', :require => false
31
+ gem 'delayed_job', '4.1.9', :require => false
47
32
  gem 'generator_spec'
48
- gem 'girl_friday', '>= 0.11.1'
49
- gem 'redis'
33
+ gem 'redis', '<= 4.8.0'
50
34
  gem 'resque'
35
+ gem 'secure_headers', '~> 6.3.2', :require => false
51
36
  gem 'simplecov'
52
37
 
53
38
  unless is_jruby
@@ -0,0 +1,52 @@
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.5'
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', '>= 6.4.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 and ruby 2.5.x
28
+ gem 'sinatra', :git => 'https://github.com/sinatra/sinatra', :tag =>'v2.1.0'
29
+
30
+ gem 'database_cleaner'
31
+ gem 'delayed_job', '4.1.9', :require => false
32
+ gem 'generator_spec'
33
+ gem 'redis', '<= 4.8.0'
34
+ gem 'resque'
35
+ gem 'secure_headers', '~> 6.3.2', :require => false
36
+ gem 'simplecov'
37
+
38
+ unless is_jruby
39
+ # JRuby doesn't support fork, which is required for this test helper.
40
+ gem 'rspec-command'
41
+ end
42
+
43
+ gem 'mime-types'
44
+
45
+ gem 'webmock', :require => false
46
+
47
+ gem 'aws-sdk-sqs'
48
+ gem 'shoryuken'
49
+
50
+ gem 'capistrano', :require => false
51
+
52
+ gemspec :path => '../'
@@ -0,0 +1,52 @@
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', '~> 7.0.2.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', '>= 6.4.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 and ruby 2.5.x
28
+ gem 'sinatra', :git => 'https://github.com/sinatra/sinatra', :tag =>'v2.1.0'
29
+
30
+ gem 'database_cleaner'
31
+ gem 'delayed_job', '4.1.10', :require => false
32
+ gem 'generator_spec'
33
+ gem 'redis', '<= 4.8.0'
34
+ gem 'resque'
35
+ gem 'secure_headers', '~> 6.3.2', :require => false
36
+ gem 'simplecov'
37
+
38
+ unless is_jruby
39
+ # JRuby doesn't support fork, which is required for this test helper.
40
+ gem 'rspec-command'
41
+ end
42
+
43
+ gem 'mime-types'
44
+
45
+ gem 'webmock', :require => false
46
+
47
+ gem 'aws-sdk-sqs'
48
+ gem 'shoryuken'
49
+
50
+ gem 'capistrano', :require => false
51
+
52
+ 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,23 +4,13 @@ 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
11
- class GemResolver
12
- def railties_gem
13
- Gem::Specification.find_by_name('railties')
14
- end
15
- end
16
-
17
- class LegacyGemResolver
18
- def railties_gem
19
- searcher = Gem::GemPathSearcher.new
20
- searcher.find('rails')
21
- end
22
- end
23
-
24
14
  attr_reader :command
25
15
 
26
16
  def initialize
@@ -39,7 +29,7 @@ module Rails
39
29
  end
40
30
 
41
31
  def eval_runner
42
- if Rails.version >= '5.1.0'
32
+ if Gem::Version.new(Rails.version) >= Gem::Version.new('5.1.0')
43
33
  rails5_runner
44
34
  else
45
35
  legacy_runner
@@ -49,12 +39,14 @@ module Rails
49
39
  def legacy_runner
50
40
  string_to_eval = File.read(runner_path)
51
41
 
52
- ::Rails.module_eval(<<-EOL, __FILE__, __LINE__ + 2)
42
+ ::Rails.module_eval(<<-FILE, __FILE__, __LINE__ + 1)
53
43
  #{string_to_eval}
54
- EOL
44
+ FILE
55
45
  end
56
46
 
57
47
  def rails5_runner
48
+ require 'rails/command'
49
+
58
50
  Rails::Command.invoke 'runner', ARGV
59
51
  end
60
52
 
@@ -66,12 +58,11 @@ module Rails
66
58
  end
67
59
 
68
60
  def runner_path
69
- railties_gem_dir + '/lib/rails/commands/runner.rb'
61
+ "#{railties_gem_dir}/lib/rails/commands/runner.rb"
70
62
  end
71
63
 
72
64
  def railties_gem
73
- resolver_class = Gem::Specification.respond_to?(:find_by_name) ? GemResolver : LegacyGemResolver
74
- gem = resolver_class.new.railties_gem
65
+ gem = Gem::Specification.find_by_name('railties')
75
66
 
76
67
  abort 'railties gem not found' unless gem
77
68
 
@@ -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