Sha256: 77d3a622b1e4f9bba74a7fae3eb45f46ede0e046b70ad6062c87e36df729c89f

Contents?: true

Size: 842 Bytes

Versions: 8

Compression:

Stored size: 842 Bytes

Contents

require 'faraday'

module FaradayMiddleware
  # Public: Instruments requests using Active Support.
  #
  # Measures time spent only for synchronous requests.
  #
  # Examples
  #
  #   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
  class Instrumentation < Faraday::Middleware
    dependency 'active_support/notifications'

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

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

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
agiley-faraday_middleware-0.8.3.2 lib/faraday_middleware/instrumentation.rb
agiley-faraday_middleware-0.8.3.1 lib/faraday_middleware/instrumentation.rb
faraday_middleware-0.8.4 lib/faraday_middleware/instrumentation.rb
agiley-faraday_middleware-0.8.3 lib/faraday_middleware/instrumentation.rb
faraday_middleware-0.8.3 lib/faraday_middleware/instrumentation.rb
faraday_middleware-0.8.2 lib/faraday_middleware/instrumentation.rb
faraday_middleware-0.8.1 lib/faraday_middleware/instrumentation.rb
faraday_middleware-0.8.0 lib/faraday_middleware/instrumentation.rb