Class: Faraday::Request::Instrumentation
- Inherits:
-
Middleware
- Object
- Middleware
- Faraday::Request::Instrumentation
- Defined in:
- lib/faraday/request/instrumentation.rb
Defined Under Namespace
Classes: Options
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = nil) ⇒ Instrumentation
constructor
Public: Instruments requests using Active Support.
Methods inherited from Middleware
dependency, inherited, loaded?, new
Methods included from MiddlewareRegistry
#fetch_middleware, #load_middleware, #lookup_middleware, #middleware_mutex, #register_middleware
Constructor Details
#initialize(app, options = nil) ⇒ Instrumentation
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
25 26 27 28 |
# File 'lib/faraday/request/instrumentation.rb', line 25 def initialize(app, = nil) super(app) @name, @instrumenter = Options.from().values_at(:name, :instrumenter) end |
Instance Method Details
#call(env) ⇒ Object
30 31 32 33 34 |
# File 'lib/faraday/request/instrumentation.rb', line 30 def call(env) @instrumenter.instrument(@name, env) do @app.call(env) end end |