Sha256: 91c357b168028511db16816d23d48d7623e6c90cdbbb6a46bec1dfbde085363c

Contents?: true

Size: 1021 Bytes

Versions: 5

Compression:

Stored size: 1021 Bytes

Contents

require 'sentry/sidekiq/context_filter'

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

      def call(ex, context)
        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 }
          )
        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

5 entries across 5 versions & 1 rubygems

Version Path
sentry-sidekiq-4.0.0 lib/sentry/sidekiq/error_handler.rb
sentry-sidekiq-0.2.0 lib/sentry/sidekiq/error_handler.rb
sentry-sidekiq-0.1.3 lib/sentry/sidekiq/error_handler.rb
sentry-sidekiq-0.1.2 lib/sentry/sidekiq/error_handler.rb
sentry-sidekiq-0.1.1 lib/sentry/sidekiq/error_handler.rb