Sha256: b46d09b727b5a593619197474f86b81666010cdd1107216955c1d42c5ad887d5

Contents?: true

Size: 699 Bytes

Versions: 1

Compression:

Stored size: 699 Bytes

Contents

require 'grape'
require 'active_support'

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

      def call(env)
        req = ::Rack::Request.new(env)
        method = env['REQUEST_METHOD']

        request_path = env['api.endpoint'].routes.first.route_path[1..-1].sub(/\(\.:format\)\z/, "")
        metric_name  = "grape.#{req.request_method}.#{request_path}"
        action = "#{env['PATH_INFO']}"


        ActiveSupport::Notifications.instrument(metric_name, { method: method, path: request_path, action: action, class: "API" } ) do |payload|
          @app.call(env)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
grape-appsignal-0.2.1 lib/grape-appsignal/middleware.rb