sentry-sidekiq 5.10.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: e0032fc4b32f7d021cb268513357d37f6697fcae83a4d976a9b0e011e31931e9
4
- data.tar.gz: f32997df5b2f5aab6430d5828f8a678eff2e3440fc3b55b64f1bea5ab7de752f
3
+ metadata.gz: b628ededc9e9b51565c3fe7ec69900b0a7d4d36327437a878cd1717fd0d8fdb0
4
+ data.tar.gz: '059c3ab5c661c3e0d54327aa6267384e95af830e7e7d0ab9cff9d4a15fe5a368'
5
5
  SHA512:
6
- metadata.gz: 36a7e7af214cfa651ab6a05c34735cb27ada4647a74c2ec3cf4e10af65eee47dd9cfd6bd8551c50971aede6315849f63c7fc44cefa7c8770504421cf24c3333d
7
- data.tar.gz: a74c6e2bd56eba75ad59504c87636a4de882f890af3ae97d898d2b8c9db7ff7431cc14d55aff13e4bdf44c6b287af4ff3417afad2eaa42806da585c742097119
6
+ metadata.gz: 1ee88f6a25c8132d594ecf0c1cd4fb5b116a7deec9c06d4591d5c2092a1c3d30a22961c4b51576c8e2e7471484e997a8c8ab5259e6a97e992deba2f7118d36e8
7
+ data.tar.gz: e5b27dd798035323e41c0397f7321e749fa000207567a85e8ae608df817848e3502a56c512648bc016a077a8eb8947d7f163fc95c0416b9458e3dd66dad4e2f9
data/Gemfile CHANGED
@@ -15,11 +15,21 @@ 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?
23
+ sidekiq_version = Gem::Version.new(sidekiq_version)
20
24
 
21
25
  gem "sidekiq", "~> #{sidekiq_version}"
22
- gem "rails"
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
+
32
+ gem "rails", "> 5.0.0", "< 7.1.0"
23
33
 
24
34
  if RUBY_VERSION.to_f >= 2.6
25
35
  gem "debug", github: "ruby/debug", platform: :ruby
@@ -27,4 +37,3 @@ if RUBY_VERSION.to_f >= 2.6
27
37
  end
28
38
 
29
39
  gem "pry"
30
-
data/README.md CHANGED
@@ -11,7 +11,7 @@
11
11
 
12
12
 
13
13
  [![Gem Version](https://img.shields.io/gem/v/sentry-sidekiq.svg)](https://rubygems.org/gems/sentry-sidekiq)
14
- ![Build Status](https://github.com/getsentry/sentry-ruby/workflows/sentry-sidekiq%20Test/badge.svg)
14
+ ![Build Status](https://github.com/getsentry/sentry-ruby/actions/workflows/sentry_sidekiq_test.yml/badge.svg)
15
15
  [![Coverage Status](https://img.shields.io/codecov/c/github/getsentry/sentry-ruby/master?logo=codecov)](https://codecov.io/gh/getsentry/sentry-ruby/branch/master)
16
16
  [![Gem](https://img.shields.io/gem/dt/sentry-sidekiq.svg)](https://rubygems.org/gems/sentry-sidekiq/)
17
17
  [![SemVer](https://api.dependabot.com/badges/compatibility_score?dependency-name=sentry-sidekiq&package-manager=bundler&version-scheme=semver)](https://dependabot.com/compatibility-score.html?dependency-name=sentry-sidekiq&package-manager=bundler&version-scheme=semver)
@@ -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
@@ -19,7 +19,7 @@ module Sentry
19
19
  scope.set_tags(build_tags(job["tags"]))
20
20
  scope.set_contexts(sidekiq: job.merge("queue" => queue))
21
21
  scope.set_transaction_name(context_filter.transaction_name, source: :task)
22
- transaction = start_transaction(scope, job["sentry_trace"])
22
+ transaction = start_transaction(scope, job["trace_propagation_headers"])
23
23
  scope.set_span(transaction) if transaction
24
24
 
25
25
  begin
@@ -39,9 +39,9 @@ module Sentry
39
39
  Array(tags).each_with_object({}) { |name, tags_hash| tags_hash[:"sidekiq.#{name}"] = true }
40
40
  end
41
41
 
42
- def start_transaction(scope, sentry_trace)
42
+ def start_transaction(scope, env)
43
43
  options = { name: scope.transaction_name, source: scope.transaction_source, op: OP_NAME }
44
- transaction = Sentry::Transaction.from_sentry_trace(sentry_trace, **options) if sentry_trace
44
+ transaction = Sentry.continue_trace(env, **options)
45
45
  Sentry.start_transaction(transaction: transaction, **options)
46
46
  end
47
47
 
@@ -58,9 +58,8 @@ module Sentry
58
58
  return yield unless Sentry.initialized?
59
59
 
60
60
  user = Sentry.get_current_scope.user
61
- transaction = Sentry.get_current_scope.get_transaction
62
61
  job["sentry_user"] = user unless user.empty?
63
- job["sentry_trace"] = transaction.to_sentry_trace if transaction
62
+ job["trace_propagation_headers"] ||= Sentry.get_trace_propagation_headers
64
63
  yield
65
64
  end
66
65
  end
@@ -1,5 +1,5 @@
1
1
  module Sentry
2
2
  module Sidekiq
3
- VERSION = "5.10.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.10.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.10.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-07-04 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.10.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.10.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