sentry-sidekiq 5.13.0 → 5.15.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: dbee9fb2c7ce4efbbb53923d02625f15d61a03a7fa00911441f46ae6a6ccd8bf
4
- data.tar.gz: b404496bc93b23f0bb05ef908353db8a31ed43daad05774c5e310a62be73ea23
3
+ metadata.gz: fdc1a839d4b1268fd8338afd1cb31548f22ba41596f4b070d81c9ec0c539ceb0
4
+ data.tar.gz: b631540a70804ef4a98b219a5c4e7c873ae576909d0cbd9fdb15ca011933fe72
5
5
  SHA512:
6
- metadata.gz: ec8e07f20953f3a5afc0ed33ede9b4517296a30eec2696f0b7c059bcd0fe35ec00d7bc23b9e9c847ee981a641148f0a74644d6e28e9e7023e4f8dd7db8e27349
7
- data.tar.gz: bca2a42ab5d1347818a8e1543fa75d5f04488025173e35671b3e0d400eeb2ba79835b2d0239efdb34ed1a10a427235bed0b34c300b00902f2ea4e7c805df629a
6
+ metadata.gz: 453569297ac4ee74d7701ad62d7bf0997b2d29971b61e5a8c056f74773a46bcef1e647cc41bfea4548caee3f26b56966c3eefbb517178d6f98ac26c2979170cb
7
+ data.tar.gz: 9fcf62c576fed0224dc8ca5f3d7e004bd664c22ddbe30024c8590254cfd6adfe9b811823034ff276c91032a2800af19de90c1b67de6ec4700df4b5e4aaf15046
data/Gemfile CHANGED
@@ -19,11 +19,16 @@ gem "loofah", "2.20.0" if RUBY_VERSION.to_f < 2.5
19
19
  gem "psych", "5.1.0"
20
20
 
21
21
  sidekiq_version = ENV["SIDEKIQ_VERSION"]
22
- sidekiq_version = "6.0" if sidekiq_version.nil?
22
+ sidekiq_version = "7.0" if sidekiq_version.nil?
23
23
  sidekiq_version = Gem::Version.new(sidekiq_version)
24
24
 
25
25
  gem "sidekiq", "~> #{sidekiq_version}"
26
26
 
27
+ if RUBY_VERSION.to_f >= 2.7 && sidekiq_version >= Gem::Version.new("6.0")
28
+ gem "sidekiq-cron"
29
+ gem "sidekiq-scheduler"
30
+ end
31
+
27
32
  gem "rails", "> 5.0.0", "< 7.1.0"
28
33
 
29
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.13.0"
3
+ VERSION = "5.15.0"
4
4
  end
5
5
  end
@@ -0,0 +1,67 @@
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
+ slug = klass_const.send(:sentry_monitor_slug, name: name)
54
+ klass_const.send(:sentry_monitor_check_ins,
55
+ slug: slug,
56
+ monitor_config: monitor_config)
57
+
58
+ ::Sidekiq.logger.info "Injected Sentry Crons monitor checkins into #{klass}"
59
+ end
60
+
61
+ rufus_job
62
+ end
63
+ end
64
+ end
65
+ end
66
+
67
+ 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.13.0"
25
+ spec.add_dependency "sentry-ruby", "~> 5.15.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.13.0
4
+ version: 5.15.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-11-09 00:00:00.000000000 Z
11
+ date: 2023-12-05 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.13.0
19
+ version: 5.15.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.13.0
26
+ version: 5.15.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