Sha256: 78f1fc3ac7458086681d64fa10233020e1d281aba69f599e42ae7f4bb0f39af1

Contents?: true

Size: 1.08 KB

Versions: 2

Compression:

Stored size: 1.08 KB

Contents

require 'sentry/sidekiq/context_filter'

module Sentry
  module Sidekiq
    class ErrorHandler
      SIDEKIQ_NAME = "Sidekiq".freeze

      def call(ex, context)
        return unless Sentry.initialized?
        context = Sentry::Sidekiq::ContextFilter.new.filter_context(context)

        Sentry.with_scope do |scope|
          scope.set_transaction_name transaction_from_context(context)
          Sentry.capture_exception(
            ex,
            extra: { sidekiq: context },
            hint: { background: false }
          )
        end
      end

      private

      # this will change in the future:
      # https://github.com/mperham/sidekiq/pull/3161
      def transaction_from_context(context)
        classname = (context["wrapped"] || context["class"] ||
                      (context[:job] && (context[:job]["wrapped"] || context[:job]["class"]))
                    )
        if classname
          "#{SIDEKIQ_NAME}/#{classname}"
        elsif context[:event]
          "#{SIDEKIQ_NAME}/#{context[:event]}"
        else
          SIDEKIQ_NAME
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sentry-sidekiq-4.1.1 lib/sentry/sidekiq/error_handler.rb
sentry-sidekiq-4.1.0 lib/sentry/sidekiq/error_handler.rb