Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(sentry-sidekiq): Fixed a deprecation warning in error handler #2160

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix compatibility with Sidekiq 6
  • Loading branch information
natikgadzhi authored and sl0thentr0py committed Nov 13, 2023
commit 630c2855810ba188d78b4234b2221e86c78f1da0
22 changes: 16 additions & 6 deletions sentry-sidekiq/lib/sentry/sidekiq/error_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,24 @@ class ErrorHandler

# @param ex [Exception] the exception / error that occured
# @param context [Hash or Array] Sidekiq error context
# @param sidekiq_config [Sidekiq::Config] Sidekiq configuration,
# defaults to Sidekiq's default configuration `Sidekiq.default_configuration`
# @param sidekiq_config [Sidekiq::Config, Hash] Sidekiq configuration,
# Defaults to nil.
# Sidekiq will pass the config in starting Sidekiq 7.1.5, see
# https://github.com/sidekiq/sidekiq/pull/6051
def call(ex, context, sidekiq_config = ::Sidekiq.default_configuration)
def call(ex, context, sidekiq_config = nil)
return unless Sentry.initialized?

context_filter = Sentry::Sidekiq::ContextFilter.new(context)

scope = Sentry.get_current_scope
scope.set_transaction_name(context_filter.transaction_name, source: :task) unless scope.transaction_name

# If Sentry is configured to only report an error _after_ all retries have been exhausted,
# and if the job is retryable, and have not exceeded the retry_limit,
# return early.
if Sentry.configuration.sidekiq.report_after_job_retries && retryable?(context)
retry_count = context.dig(:job, "retry_count")
if retry_count.nil? || retry_count < retry_limit(context) - 1
if retry_count.nil? || retry_count < retry_limit(context, sidekiq_config) - 1
return
end
end
Expand All @@ -43,7 +46,10 @@ def retryable?(context)
retry_option == true || (retry_option.is_a?(Integer) && retry_option.positive?)
end

def retry_limit(context)
# @return [Integer] the number of retries allowed for the job
# Tries to fetch the retry limit from the job config first,
# then falls back to Sidekiq's configuration.
def retry_limit(context, sidekiq_config)
limit = context.dig(:job, "retry")

case limit
Expand All @@ -52,7 +58,11 @@ def retry_limit(context)
when TrueClass
max_retries =
if WITH_SIDEKIQ_7
::Sidekiq.default_configuration[:max_retries]
# Sidekiq 7.1.5+ passes the config to the error handler, so we should use that.
# Sidekiq 7.0 -> 7.1.5 provides ::Sidekiq.default_configuration.
sidekiq_config.is_a?(::Sidekiq::Config) ?
sidekiq_config[:max_retries] :
::Sidekiq.default_configuration[:max_retries]
else
::Sidekiq.options[:max_retries]
end
Expand Down