Class: Librato::Grape::Middleware
- Inherits:
-
Grape::Middleware::Base
- Object
- Grape::Middleware::Base
- Librato::Grape::Middleware
- Defined in:
- lib/grape-librato/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-librato/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 |
# File 'lib/grape-librato/middleware.rb', line 11 def call(env) req = ::Rack::Request.new(env) request_path = env['api.endpoint'].routes.first.route_path[1..-1].gsub("/", ".").sub(/\(\.:format\)\z/, "") metric_name = "grape.#{req.request_method}.#{request_path}" Librato.increment metric_name Librato.timing "#{metric_name}.time" do @app.call(env) end end |