Sha256: 8325e68b8fbc651b5597634d3454b3915aacee088d325720b7668fda7ec5200e

Contents?: true

Size: 1.64 KB

Versions: 14

Compression:

Stored size: 1.64 KB

Contents

module Raven
  class Rails
    module ActiveJobExtensions
      ALREADY_SUPPORTED_SENTRY_ADAPTERS = %w(
        ActiveJob::QueueAdapters::SidekiqAdapter
        ActiveJob::QueueAdapters::DelayedJobAdapter
      ).freeze

      def self.included(base)
        base.class_eval do
          around_perform do |job, block|
            capture_and_reraise_with_sentry(job, block)
          end
        end
      end

      def capture_and_reraise_with_sentry(job, block)
        block.call
      rescue Exception => exception # rubocop:disable Lint/RescueException
        return if rescue_with_handler(exception)
        unless already_supported_by_specific_integration?(job)
          Raven.capture_exception(exception, :extra => raven_context(job))
        end
        raise exception
      ensure
        Context.clear!
        BreadcrumbBuffer.clear!
      end

      def already_supported_by_specific_integration?(job)
        if ::Rails.version.to_f < 5.0
          ALREADY_SUPPORTED_SENTRY_ADAPTERS.include?(job.class.queue_adapter.to_s)
        else
          ALREADY_SUPPORTED_SENTRY_ADAPTERS.include?(job.class.queue_adapter.class.to_s)
        end
      end

      def raven_context(job)
        ctx = {
          :active_job => job.class.name,
          :arguments => job.arguments,
          :scheduled_at => job.scheduled_at,
          :job_id => job.job_id,
          :locale => job.locale
        }
        # Add provider_job_id details if Rails 5
        if job.respond_to?(:provider_job_id)
          ctx[:provider_job_id] = job.provider_job_id
        end

        ctx
      end
    end
  end
end

class ActiveJob::Base
  include Raven::Rails::ActiveJobExtensions
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
sentry-raven-2.12.3 lib/raven/integrations/rails/active_job.rb
sentry-raven-2.12.2 lib/raven/integrations/rails/active_job.rb
sentry-raven-2.12.1 lib/raven/integrations/rails/active_job.rb
sentry-raven-2.12.0 lib/raven/integrations/rails/active_job.rb
sentry-raven-2.11.3 lib/raven/integrations/rails/active_job.rb
sentry-raven-2.11.2 lib/raven/integrations/rails/active_job.rb
sentry-raven-2.11.1 lib/raven/integrations/rails/active_job.rb
sentry-raven-2.11.0 lib/raven/integrations/rails/active_job.rb
sentry-raven-2.10.0 lib/raven/integrations/rails/active_job.rb
sentry-raven-2.9.0 lib/raven/integrations/rails/active_job.rb
sentry-raven-2.8.0 lib/raven/integrations/rails/active_job.rb
sentry-raven-2.7.4 lib/raven/integrations/rails/active_job.rb
sentry-raven-2.7.3 lib/raven/integrations/rails/active_job.rb
alec-gem-2.7.2 lib/raven/integrations/rails/active_job.rb