Class: FaradayMiddleware::Instrumentation
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- FaradayMiddleware::Instrumentation
- Defined in:
- lib/faraday_middleware/instrumentation.rb
Overview
Public: Instruments requests using Active Support.
Measures time spent only for synchronous requests.
Examples
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
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.
25 26 27 28 |
# File 'lib/faraday_middleware/instrumentation.rb', line 25 def initialize(app, = {}) super(app) @name = .fetch(:name, 'request.faraday') end |
Instance Method Details
#call(env) ⇒ Object
30 31 32 33 34 |
# File 'lib/faraday_middleware/instrumentation.rb', line 30 def call(env) ::ActiveSupport::Notifications.instrument(@name, env) do @app.call(env) end end |