lib/dry/monitor/rack/middleware.rb in dry-monitor-1.0.0 vs lib/dry/monitor/rack/middleware.rb in dry-monitor-1.0.1
- old
+ new
@@ -12,16 +12,17 @@
Notifications.register_event(REQUEST_STOP)
Notifications.register_event(REQUEST_ERROR)
attr_reader :app, :notifications
- def initialize(*args)
+ def initialize(*args, clock: CLOCK)
@notifications, @app = *args
+ @clock = clock
end
- def new(app, *_args, &_block)
- self.class.new(notifications, app)
+ def new(app, *_args, clock: @clock, &_block)
+ self.class.new(notifications, app, clock: clock)
end
def on(event_id, &block)
notifications.subscribe(:"rack.request.#{event_id}", &block)
end
@@ -30,10 +31,10 @@
notifications.instrument(:"rack.request.#{event_id}", *args, &block)
end
def call(env)
notifications.start(REQUEST_START, env: env)
- response, time = CLOCK.measure { app.call(env) }
+ response, time = @clock.measure { app.call(env) }
notifications.stop(REQUEST_STOP, env: env, time: time, status: response[0])
response
end
end
end