Class: Dry::Monitor::Rack::Middleware
- Inherits:
-
Object
- Object
- Dry::Monitor::Rack::Middleware
- Defined in:
- lib/dry/monitor/rack/middleware.rb
Constant Summary collapse
- REQUEST_START =
:"rack.request.start"
- REQUEST_STOP =
:"rack.request.stop"
- REQUEST_ERROR =
:"rack.request.error"
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#notifications ⇒ Object
readonly
Returns the value of attribute notifications.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(*args, clock: CLOCK) ⇒ Middleware
constructor
A new instance of Middleware.
- #instrument(event_id, *args, &block) ⇒ Object
- #new(app, *_args, clock: @clock, &_block) ⇒ Object
- #on(event_id, &block) ⇒ Object
Constructor Details
#initialize(*args, clock: CLOCK) ⇒ Middleware
Returns a new instance of Middleware.
17 18 19 20 |
# File 'lib/dry/monitor/rack/middleware.rb', line 17 def initialize(*args, clock: CLOCK) @notifications, @app = *args @clock = clock end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
15 16 17 |
# File 'lib/dry/monitor/rack/middleware.rb', line 15 def app @app end |
#notifications ⇒ Object (readonly)
Returns the value of attribute notifications.
15 16 17 |
# File 'lib/dry/monitor/rack/middleware.rb', line 15 def notifications @notifications end |
Instance Method Details
#call(env) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/dry/monitor/rack/middleware.rb', line 34 def call(env) notifications.start(REQUEST_START, env: env) response, time = @clock.measure { app.call(env) } notifications.stop(REQUEST_STOP, env: env, time: time, status: response[0]) response end |
#instrument(event_id, *args, &block) ⇒ Object
30 31 32 |
# File 'lib/dry/monitor/rack/middleware.rb', line 30 def instrument(event_id, *args, &block) notifications.instrument(:"rack.request.#{event_id}", *args, &block) end |
#new(app, *_args, clock: @clock, &_block) ⇒ Object
22 23 24 |
# File 'lib/dry/monitor/rack/middleware.rb', line 22 def new(app, *_args, clock: @clock, &_block) self.class.new(notifications, app, clock: clock) end |
#on(event_id, &block) ⇒ Object
26 27 28 |
# File 'lib/dry/monitor/rack/middleware.rb', line 26 def on(event_id, &block) notifications.subscribe(:"rack.request.#{event_id}", &block) end |