Class: Pliny::Middleware::Instruments
- Inherits:
-
Object
- Object
- Pliny::Middleware::Instruments
- Defined in:
- lib/pliny/middleware/instruments.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ Instruments
constructor
A new instance of Instruments.
Constructor Details
#initialize(app) ⇒ Instruments
Returns a new instance of Instruments.
3 4 5 |
# File 'lib/pliny/middleware/instruments.rb', line 3 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/pliny/middleware/instruments.rb', line 7 def call(env) start = Time.now data = { instrumentation: true, method: env["REQUEST_METHOD"], path: env["PATH_INFO"] } Pliny.log(data.merge(at: "start")) status, headers, response = @app.call(env) if route = env["sinatra.route"] data.merge!(route_signature: route.split(" ").last) end elapsed = (Time.now - start).to_f Pliny.log(data.merge( at: "finish", status: status, length: headers["Content-Length"], elapsed: elapsed )) [status, headers, response] end |