Sha256: 6f30b7eb6536b4bd95af1e320e37e2522bd4ba4deced4bd31e1f5ea1fd8af40d

Contents?: true

Size: 989 Bytes

Versions: 1

Compression:

Stored size: 989 Bytes

Contents

# frozen_string_literal: true

module ElasticAPM
  # @api private
  module Spies
    # @api private
    class ResqueSpy
      TYPE = 'Resque'

      def install
        install_perform_spy
        install_after_fork_hook
      end

      def install_after_fork_hook
        ::Resque.after_fork do
          ElasticAPM.restart
        end
      end

      def install_perform_spy
        ::Resque::Job.class_eval do
          alias :perform_without_elastic_apm :perform

          def perform
            name = @payload && @payload['class']&.name
            transaction = ElasticAPM.start_transaction(name, TYPE)
            perform_without_elastic_apm
            transaction.done 'success'
          rescue ::Exception => e
            ElasticAPM.report(e, handled: false)
            transaction.done 'error'
            raise
          ensure
            ElasticAPM.end_transaction
          end
        end
      end
    end

    register 'Resque', 'resque', ResqueSpy.new
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
elastic-apm-3.6.0 lib/elastic_apm/spies/resque.rb