module Sentry::Rails::ActiveJobExtensions

def capture_and_reraise_with_sentry(job, scope, block)

def capture_and_reraise_with_sentry(job, scope, block)
  scope.set_transaction_name(job.class.name)
  transaction = Sentry.start_transaction(name: scope.transaction_name, op: "active_job")
  scope.set_span(transaction) if transaction
  block.call
  finish_transaction(transaction, 200)
rescue Exception => e # rubocop:disable Lint/RescueException
  rescue_handler_result = rescue_with_handler(e)
  finish_transaction(transaction, 500)
  return rescue_handler_result if rescue_handler_result
  Sentry::Rails.capture_exception(
    e,
    extra: sentry_context(job),
    tags: {
      job_id: job.job_id,
      provider_job_id: job.provider_job_id
    }
  )
  raise e
end