Class: MonoVM::Whois::Transport::Middleware::Instrumentation
- Inherits:
-
Middleware::Base
- Object
- Middleware::Base
- MonoVM::Whois::Transport::Middleware::Instrumentation
- Defined in:
- lib/monovm/whois/transport/middleware/instrumentation.rb
Overview
Reports every exchange to a subscriber.
A registrar running this at volume needs to know which registries are slow and which are refusing, and that is the host application's concern, not this library's. So nothing is logged here — an event is handed to whatever was injected, and the caller decides whether it becomes a log line, a StatsD counter or nothing at all.
Instance Method Summary collapse
- #fetch(query:, endpoint:) ⇒ Object
-
#initialize(app, subscriber:) ⇒ Instrumentation
constructor
A new instance of Instrumentation.
Constructor Details
#initialize(app, subscriber:) ⇒ Instrumentation
Returns a new instance of Instrumentation.
18 19 20 21 |
# File 'lib/monovm/whois/transport/middleware/instrumentation.rb', line 18 def initialize(app, subscriber:) @subscriber = subscriber super(app) end |
Instance Method Details
#fetch(query:, endpoint:) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/monovm/whois/transport/middleware/instrumentation.rb', line 23 def fetch(query:, endpoint:) started = Process.clock_gettime(Process::CLOCK_MONOTONIC) begin response = app.fetch(query: query, endpoint: endpoint) rescue StandardError => e publish( query: query, endpoint: endpoint, outcome: :error, error: e.class.name, message: e., elapsed: Process.clock_gettime(Process::CLOCK_MONOTONIC) - started ) raise end publish( query: query, endpoint: endpoint, outcome: :ok, status: response.status, bytes: response.body.length, elapsed: Process.clock_gettime(Process::CLOCK_MONOTONIC) - started ) response end |