Sha256: e1d113bb41f9e0e079f3d2a764c75ec7058074ffd1fe6a6b386e1e4eea34a3cc

Contents?: true

Size: 793 Bytes

Versions: 1

Compression:

Stored size: 793 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}"
        metric_name = metric_name.gsub(/\/:?/, '.')

        action = "#{env['PATH_INFO']}"
        action = action.gsub(/\//, '::')

        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.2 lib/grape-appsignal/middleware.rb