Class: FaradayStack::Instrumentation

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/faraday_stack/instrumentation.rb

Overview

Measures request time only in synchronous request mode. Sample subscriber:

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

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ Instrumentation

Returns a new instance of Instrumentation.



14
15
16
17
18
# File 'lib/faraday_stack/instrumentation.rb', line 14

def initialize(app, options = {})
  super(app)
  @options = options
  @name = options[:name] || 'request.faraday'
end

Instance Method Details

#call(env) ⇒ Object



20
21
22
23
24
# File 'lib/faraday_stack/instrumentation.rb', line 20

def call(env)
  ActiveSupport::Notifications.instrument(@name, env) do
    @app.call(env)
  end
end