Sha256: 89b7ecb711684163eae40943e7adf73306a8e5e4e5ea7d8de707ba3b4cd4b22a

Contents?: true

Size: 1.24 KB

Versions: 74

Compression:

Stored size: 1.24 KB

Contents

module Appsignal
  module Grape
    class Middleware < ::Grape::Middleware::Base
      def initialize(app)
        @app = app
      end

      def call(env)
        if Appsignal.active?
          call_with_appsignal_monitoring(env)
        else
          @app.call(env)
        end
      end

      def call_with_appsignal_monitoring(env)
        request      = ::Rack::Request.new(env)
        transaction  = Appsignal::Transaction.create(
          SecureRandom.uuid,
          Appsignal::Transaction::HTTP_REQUEST,
          request
        )
        begin
          @app.call(env)
        rescue => error
          transaction.set_error(error)
          raise error
        ensure
          api_endpoint = env['api.endpoint']
          if api_endpoint && options = api_endpoint.options
            method = options[:method].first
            klass  = options[:for]
            action = options[:path].first
            transaction.set_action("#{method}::#{klass}##{action}")
          end
          transaction.set_http_or_background_queue_start
          transaction.set_metadata('path', request.path)
          transaction.set_metadata('method', env['REQUEST_METHOD'])
          Appsignal::Transaction.complete_current!
        end
      end
    end
  end
end

Version data entries

74 entries across 74 versions & 1 rubygems

Version Path
appsignal-1.4.0.beta.1 lib/appsignal/integrations/grape.rb
appsignal-1.3.6 lib/appsignal/integrations/grape.rb
appsignal-1.3.6.beta.1 lib/appsignal/integrations/grape.rb
appsignal-1.3.5 lib/appsignal/integrations/grape.rb
appsignal-1.3.5.beta.1 lib/appsignal/integrations/grape.rb
appsignal-1.3.4 lib/appsignal/integrations/grape.rb
appsignal-1.3.3 lib/appsignal/integrations/grape.rb
appsignal-1.4.0.alpha.2 lib/appsignal/integrations/grape.rb
appsignal-1.4.0.alpha.1 lib/appsignal/integrations/grape.rb
appsignal-1.3.2 lib/appsignal/integrations/grape.rb
appsignal-1.3.1 lib/appsignal/integrations/grape.rb
appsignal-1.3.0 lib/appsignal/integrations/grape.rb
appsignal-1.3.0.beta.3 lib/appsignal/integrations/grape.rb
appsignal-1.3.0.beta.2 lib/appsignal/integrations/grape.rb
appsignal-1.3.0.beta.1 lib/appsignal/integrations/grape.rb
appsignal-1.2.5 lib/appsignal/integrations/grape.rb
appsignal-1.2.4 lib/appsignal/integrations/grape.rb
appsignal-1.2.4.beta.4 lib/appsignal/integrations/grape.rb
appsignal-1.2.4.beta.3 lib/appsignal/integrations/grape.rb
appsignal-1.2.4.beta.2 lib/appsignal/integrations/grape.rb