Sha256: d113a6ff61338d653a024468cbb39ab2aea061f3db8e7d7c03097945d5cdbe0d

Contents?: true

Size: 747 Bytes

Versions: 1

Compression:

Stored size: 747 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)
        method = env['REQUEST_METHOD']
        metric_path = env['PATH_INFO'].nil? ? ".api" : env['PATH_INFO'].gsub("/", ".")
        request_path = env['api.endpoint'].routes.first.route_path[1..-1].gsub(/\(\.:format\)\z/, "")

        metric_name  = "process_action.grape#{metric_path}"
        action = "#{method}#{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.1.2 lib/grape-appsignal/middleware.rb