Sha256: 74172b0378b2e202aa10bb6484e317e9d710d596dd2d9bed0f622ca691608d4c

Contents?: true

Size: 1.13 KB

Versions: 15

Compression:

Stored size: 1.13 KB

Contents

require 'ears/middleware'

module Ears
  module Middlewares
    # A middleware that automatically wraps {Ears::Consumer#work} in an Appsignal transaction.
    class Appsignal < Middleware
      # @param [Hash] opts The options for the middleware.
      # @option opts [String] :transaction_name The name of the Appsignal transaction.
      # @option opts [String] :class_name The name of the class you want to monitor.
      def initialize(opts)
        super()
        @transaction_name = opts.fetch(:transaction_name)
        @class_name = opts.fetch(:class_name)
      end

      def call(delivery_info, metadata, payload, app)
        start_transaction do
          begin
            app.call(delivery_info, metadata, payload)
          rescue => e
            ::Appsignal.set_error(e)
            raise
          end
        end
      end

      private

      attr_reader :transaction_name, :class_name

      def start_transaction(&block)
        ::Appsignal.monitor_transaction(
          transaction_name,
          class: class_name,
          method: 'work',
          queue_start: Time.now.utc,
          &block
        )
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
ears-0.13.0 lib/ears/middlewares/appsignal.rb
ears-0.12.0 lib/ears/middlewares/appsignal.rb
ears-0.11.2 lib/ears/middlewares/appsignal.rb
ears-0.11.1 lib/ears/middlewares/appsignal.rb
ears-0.11.0 lib/ears/middlewares/appsignal.rb
ears-0.10.1 lib/ears/middlewares/appsignal.rb
ears-0.10.0 lib/ears/middlewares/appsignal.rb
ears-0.9.3 lib/ears/middlewares/appsignal.rb
ears-0.9.2 lib/ears/middlewares/appsignal.rb
ears-0.9.0 lib/ears/middlewares/appsignal.rb
ears-0.8.2 lib/ears/middlewares/appsignal.rb
ears-0.8.1 lib/ears/middlewares/appsignal.rb
ears-0.8.0 lib/ears/middlewares/appsignal.rb
ears-0.7.2 lib/ears/middlewares/appsignal.rb
ears-0.7.1 lib/ears/middlewares/appsignal.rb