Class: Chronos::Integrations::FaradayMiddleware
- Inherits:
-
Object
- Object
- Chronos::Integrations::FaradayMiddleware
- Defined in:
- lib/chronos/integrations/faraday.rb
Overview
Optional Faraday middleware for outbound timing and W3C propagation.
Instance Method Summary collapse
- #call(environment) ⇒ Object
-
#initialize(app, options = {}) ⇒ FaradayMiddleware
constructor
A new instance of FaradayMiddleware.
Constructor Details
#initialize(app, options = {}) ⇒ FaradayMiddleware
Returns a new instance of FaradayMiddleware.
14 15 16 17 18 |
# File 'lib/chronos/integrations/faraday.rb', line 14 def initialize(app, = {}) @app = app @notifier = [:notifier] || Chronos @clock = [:clock] || proc { Process.clock_gettime(Process::CLOCK_MONOTONIC) } end |
Instance Method Details
#call(environment) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/chronos/integrations/faraday.rb', line 20 def call(environment) started_at = @clock.call inject_headers(environment) response = @app.call(environment) if response.respond_to?(:on_complete) response.on_complete { |completed| record(completed, started_at, nil) } else record(environment, started_at, nil) end response rescue StandardError => error record(environment, started_at, error) if started_at raise end |