Class: FaradayStack::Instrumentation
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- FaradayStack::Instrumentation
- 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
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ Instrumentation
constructor
A new instance of Instrumentation.
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, = {}) super(app) @options = @name = [: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 |