Class: Appsignal::Grape::Middleware
- Inherits:
-
Grape::Middleware::Base
- Object
- Grape::Middleware::Base
- Appsignal::Grape::Middleware
- Defined in:
- lib/grape-appsignal/middleware.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app) ⇒ Middleware
Returns a new instance of Middleware.
7 8 9 |
# File 'lib/grape-appsignal/middleware.rb', line 7 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/grape-appsignal/middleware.rb', line 11 def call(env) req = ::Rack::Request.new(env) method = env['REQUEST_METHOD'] api_endpoint = env['api.endpoint'] method_name = api_endpoint.method_name.gsub(/ ?[ \/]/, '/') if api_endpoint && api_endpoint.method_name method_name = method_name.gsub(/\/\//, '/') if method_name request_path = api_endpoint.routes.first.route_path[1..-1].sub(/\(\.:format\)\z/, "") metric_name = "process_action.grape.#{req.request_method}.#{request_path}" metric_name = metric_name.gsub(/\/:?/, '.') action = "Grape" action = action + "(#{api_endpoint.settings[:version].first})" if api_endpoint.settings[:version] && api_endpoint.settings[:version].first action = action + "(#{api_endpoint.settings[:root_prefix]})" if api_endpoint.settings && api_endpoint.settings[:root_prefix] action = action + "::#{method_name}" #action = action.gsub(/ ?/, '/') ActiveSupport::Notifications.instrument(metric_name, { method: method, path: request_path, action: action, class: "API" } ) do |payload| @app.call(env) end end |