sentry-sidekiq 5.12.0 → 5.14.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d8ca295fef5c66be6f425299d140e11348cfe2e32e02cd57a5edc387eae496eb
4
- data.tar.gz: 9ffdbbc597aed137b54eb5c9828a86cea335cb58fceab63661426da2c06d3169
3
+ metadata.gz: b628ededc9e9b51565c3fe7ec69900b0a7d4d36327437a878cd1717fd0d8fdb0
4
+ data.tar.gz: '059c3ab5c661c3e0d54327aa6267384e95af830e7e7d0ab9cff9d4a15fe5a368'
5
5
  SHA512:
6
- metadata.gz: cb9e68ea2e6a0c3eeae1022b309973e2785ced4eb555122a1aab43b25073ee8050ddd756f0c9310cbfe7ffc691834f22d616289d423514ab10556821e8eb1f58
7
- data.tar.gz: 7c23f656463f868e77cecfba94741150604ecf94a1e6411270266855b7085e8c5ae3d9f2f6ca3bd93f79173bebe72e0b1950288ded7a7c679505cada2595b715
6
+ metadata.gz: 1ee88f6a25c8132d594ecf0c1cd4fb5b116a7deec9c06d4591d5c2092a1c3d30a22961c4b51576c8e2e7471484e997a8c8ab5259e6a97e992deba2f7118d36e8
7
+ data.tar.gz: e5b27dd798035323e41c0397f7321e749fa000207567a85e8ae608df817848e3502a56c512648bc016a077a8eb8947d7f163fc95c0416b9458e3dd66dad4e2f9
data/Gemfile CHANGED
@@ -15,17 +15,20 @@ gem "rexml"
15
15
  # loofah changed the required ruby version in a patch so we need to explicitly pin it
16
16
  gem "loofah", "2.20.0" if RUBY_VERSION.to_f < 2.5
17
17
 
18
+ # For https://github.com/ruby/psych/issues/655
19
+ gem "psych", "5.1.0"
20
+
18
21
  sidekiq_version = ENV["SIDEKIQ_VERSION"]
19
- sidekiq_version = "6.0" if sidekiq_version.nil?
22
+ sidekiq_version = "7.0" if sidekiq_version.nil?
20
23
  sidekiq_version = Gem::Version.new(sidekiq_version)
21
24
 
22
- if sidekiq_version >= Gem::Version.new("7.0")
23
- # This is for a unreleased fix for sidekiq 7
24
- # https://github.com/sidekiq/sidekiq/commit/b7236f814ccb61d3b1e6fc5251ed3d3ac7428eb3
25
- gem "sidekiq", github: "sidekiq/sidekiq"
26
- else
27
- gem "sidekiq", "~> #{sidekiq_version}"
25
+ gem "sidekiq", "~> #{sidekiq_version}"
26
+
27
+ if RUBY_VERSION.to_f >= 2.7 && sidekiq_version >= Gem::Version.new("6.0")
28
+ gem "sidekiq-cron"
29
+ gem "sidekiq-scheduler"
28
30
  end
31
+
29
32
  gem "rails", "> 5.0.0", "< 7.1.0"
30
33
 
31
34
  if RUBY_VERSION.to_f >= 2.6
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Try requiring sidekiq-cron to ensure it's loaded before the integration.
4
+ # If sidekiq-cron is not available, do nothing.
5
+ begin
6
+ require "sidekiq-cron"
7
+ rescue LoadError
8
+ return
9
+ end
10
+
11
+ module Sentry
12
+ module Sidekiq
13
+ module Cron
14
+ module Job
15
+ def save
16
+ # validation failed, do nothing
17
+ return false unless super
18
+
19
+ # fail gracefully if can't find class
20
+ klass_const =
21
+ begin
22
+ ::Sidekiq::Cron::Support.constantize(klass.to_s)
23
+ rescue NameError
24
+ return true
25
+ end
26
+
27
+ # only patch if not explicitly included in job by user
28
+ unless klass_const.send(:ancestors).include?(Sentry::Cron::MonitorCheckIns)
29
+ klass_const.send(:include, Sentry::Cron::MonitorCheckIns)
30
+ klass_const.send(:sentry_monitor_check_ins,
31
+ slug: name,
32
+ monitor_config: Sentry::Cron::MonitorConfig.from_crontab(cron))
33
+ end
34
+
35
+ true
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ Sentry.register_patch(:sidekiq_cron, Sentry::Sidekiq::Cron::Job, ::Sidekiq::Cron::Job)
@@ -5,7 +5,13 @@ module Sentry
5
5
  class ErrorHandler
6
6
  WITH_SIDEKIQ_7 = ::Gem::Version.new(::Sidekiq::VERSION) >= ::Gem::Version.new("7.0")
7
7
 
8
- def call(ex, context)
8
+ # @param ex [Exception] the exception / error that occured
9
+ # @param context [Hash or Array] Sidekiq error context
10
+ # @param sidekiq_config [Sidekiq::Config, Hash] Sidekiq configuration,
11
+ # Defaults to nil.
12
+ # Sidekiq will pass the config in starting Sidekiq 7.1.5, see
13
+ # https://github.com/sidekiq/sidekiq/pull/6051
14
+ def call(ex, context, sidekiq_config = nil)
9
15
  return unless Sentry.initialized?
10
16
 
11
17
  context_filter = Sentry::Sidekiq::ContextFilter.new(context)
@@ -13,9 +19,12 @@ module Sentry
13
19
  scope = Sentry.get_current_scope
14
20
  scope.set_transaction_name(context_filter.transaction_name, source: :task) unless scope.transaction_name
15
21
 
22
+ # If Sentry is configured to only report an error _after_ all retries have been exhausted,
23
+ # and if the job is retryable, and have not exceeded the retry_limit,
24
+ # return early.
16
25
  if Sentry.configuration.sidekiq.report_after_job_retries && retryable?(context)
17
26
  retry_count = context.dig(:job, "retry_count")
18
- if retry_count.nil? || retry_count < retry_limit(context) - 1
27
+ if retry_count.nil? || retry_count < retry_limit(context, sidekiq_config) - 1
19
28
  return
20
29
  end
21
30
  end
@@ -37,7 +46,10 @@ module Sentry
37
46
  retry_option == true || (retry_option.is_a?(Integer) && retry_option.positive?)
38
47
  end
39
48
 
40
- def retry_limit(context)
49
+ # @return [Integer] the number of retries allowed for the job
50
+ # Tries to fetch the retry limit from the job config first,
51
+ # then falls back to Sidekiq's configuration.
52
+ def retry_limit(context, sidekiq_config)
41
53
  limit = context.dig(:job, "retry")
42
54
 
43
55
  case limit
@@ -46,7 +58,11 @@ module Sentry
46
58
  when TrueClass
47
59
  max_retries =
48
60
  if WITH_SIDEKIQ_7
49
- ::Sidekiq.default_configuration[:max_retries]
61
+ # Sidekiq 7.1.5+ passes the config to the error handler, so we should use that.
62
+ # Sidekiq 7.0 -> 7.1.5 provides ::Sidekiq.default_configuration.
63
+ sidekiq_config.is_a?(::Sidekiq::Config) ?
64
+ sidekiq_config[:max_retries] :
65
+ ::Sidekiq.default_configuration[:max_retries]
50
66
  else
51
67
  ::Sidekiq.options[:max_retries]
52
68
  end
@@ -1,5 +1,5 @@
1
1
  module Sentry
2
2
  module Sidekiq
3
- VERSION = "5.12.0"
3
+ VERSION = "5.14.0"
4
4
  end
5
5
  end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Try to require sidekiq-scheduler to make sure it's loaded before the integration.
4
+ begin
5
+ require "sidekiq-scheduler"
6
+ rescue LoadError
7
+ return
8
+ end
9
+
10
+ # If we've loaded sidekiq-scheduler, but the API changed,
11
+ # and the Scheduler class is not there, fail gracefully.
12
+ return unless defined?(::SidekiqScheduler::Scheduler)
13
+
14
+ module Sentry
15
+ module SidekiqScheduler
16
+ module Scheduler
17
+ def new_job(name, interval_type, config, schedule, options)
18
+ # Schedule the job upstream first
19
+ # SidekiqScheduler does not validate schedules
20
+ # It will fail with an error if the schedule in the config is invalid.
21
+ # If this errors out, let it fall through.
22
+ rufus_job = super
23
+
24
+ klass = config.fetch("class")
25
+ return rufus_job unless klass
26
+
27
+ # Constantize the job class, and fail gracefully if it could not be found
28
+ klass_const =
29
+ begin
30
+ Object.const_get(klass)
31
+ rescue NameError
32
+ return rufus_job
33
+ end
34
+
35
+ # For cron, every, or interval jobs — grab their schedule.
36
+ # Rufus::Scheduler::EveryJob stores it's frequency in seconds,
37
+ # so we convert it to minutes before passing in to the monitor.
38
+ monitor_config = case interval_type
39
+ when "cron"
40
+ Sentry::Cron::MonitorConfig.from_crontab(schedule)
41
+ when "every", "interval"
42
+ Sentry::Cron::MonitorConfig.from_interval(rufus_job.frequency.to_i / 60, :minute)
43
+ end
44
+
45
+ # If we couldn't build a monitor config, it's either an error, or
46
+ # it's a one-time job (interval_type is in, or at), in which case
47
+ # we should not make a monitof for it automaticaly.
48
+ return rufus_job if monitor_config.nil?
49
+
50
+ # only patch if not explicitly included in job by user
51
+ unless klass_const.send(:ancestors).include?(Sentry::Cron::MonitorCheckIns)
52
+ klass_const.send(:include, Sentry::Cron::MonitorCheckIns)
53
+ klass_const.send(:sentry_monitor_check_ins,
54
+ slug: name,
55
+ monitor_config: monitor_config)
56
+
57
+ ::Sidekiq.logger.info "Injected Sentry Crons monitor checkins into #{klass}"
58
+ end
59
+
60
+ rufus_job
61
+ end
62
+ end
63
+ end
64
+ end
65
+
66
+ Sentry.register_patch(:sidekiq_scheduler, Sentry::SidekiqScheduler::Scheduler, ::SidekiqScheduler::Scheduler)
@@ -39,3 +39,7 @@ Sidekiq.configure_client do |config|
39
39
  chain.add Sentry::Sidekiq::SentryContextClientMiddleware
40
40
  end
41
41
  end
42
+
43
+ # patches
44
+ require "sentry/sidekiq/cron/job"
45
+ require "sentry/sidekiq-scheduler/scheduler"
@@ -22,6 +22,6 @@ Gem::Specification.new do |spec|
22
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
23
  spec.require_paths = ["lib"]
24
24
 
25
- spec.add_dependency "sentry-ruby", "~> 5.12.0"
25
+ spec.add_dependency "sentry-ruby", "~> 5.14.0"
26
26
  spec.add_dependency "sidekiq", ">= 3.0"
27
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sentry-sidekiq
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.12.0
4
+ version: 5.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sentry Team
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-10-10 00:00:00.000000000 Z
11
+ date: 2023-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sentry-ruby
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 5.12.0
19
+ version: 5.14.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 5.12.0
26
+ version: 5.14.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: sidekiq
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -61,8 +61,10 @@ files:
61
61
  - example/config/sidekiq.yml
62
62
  - example/error_worker.rb
63
63
  - lib/sentry-sidekiq.rb
64
+ - lib/sentry/sidekiq-scheduler/scheduler.rb
64
65
  - lib/sentry/sidekiq/configuration.rb
65
66
  - lib/sentry/sidekiq/context_filter.rb
67
+ - lib/sentry/sidekiq/cron/job.rb
66
68
  - lib/sentry/sidekiq/error_handler.rb
67
69
  - lib/sentry/sidekiq/sentry_context_middleware.rb
68
70
  - lib/sentry/sidekiq/version.rb