class Faraday::Request::Instrumentation

Middleware for instrumenting Requests.

Constants

Options

Options class used in Request::Instrumentation class.

Public Class Methods

Instruments requests using Active Support.

Measures time spent only for synchronous requests.

@example Using ActiveSupport::Notifications to measure time spent

for Faraday requests.
ActiveSupport::Notifications
  .subscribe('request.faraday') do |name, starts, ends, _, env|
  url = env[:url]
  http_method = env[:method].to_s.upcase
  duration = ends - starts
  $stderr.puts '[%s] %s %s (%.3f s)' %
    [url.host, http_method, url.request_uri, duration]
end

@param app [#call] @param options [nil, Hash] Options hash @option options [String] :name (‘request.faraday’)

Name of the instrumenter

@option options [Class] :instrumenter (ActiveSupport::Notifications)

Active Support instrumenter class.
Calls superclass method Faraday::Middleware::new
# File lib/faraday/request/instrumentation.rb, line 42
def initialize(app, options = nil)
  super(app)
  @name, @instrumenter = Options.from(options)
                                .values_at(:name, :instrumenter)
end

Public Instance Methods

@param env [Faraday::Env]

# File lib/faraday/request/instrumentation.rb, line 49
def call(env)
  @instrumenter.instrument(@name, env) do
    @app.call(env)
  end
end