class HTTP::Features::Instrumentation

Instrument requests and responses. Expects an ActiveSupport::Notifications-compatible instrumenter. Defaults to use a namespace of 'http' which may be overridden with a `:namespace` param. Emits a single event like `“request.{namespace}”`, eg `“request.http”`. Be sure to specify the instrumenter when enabling the feature:

HTTP
  .use(instrumentation: {instrumenter: ActiveSupport::Notifications.instrumenter})
  .get("https://example.com/")

Emits two events on every request:

* `start_request.http` before the request is made, so you can log the reqest being started
* `request.http` after the response is recieved, and contains `start`
  and `finish` so the duration of the request can be calculated.

Attributes

error_name[R]
instrumenter[R]
name[R]

Public Class Methods

new(instrumenter: NullInstrumenter.new, namespace: "http") click to toggle source
# File lib/http/features/instrumentation.rb, line 24
def initialize(instrumenter: NullInstrumenter.new, namespace: "http")
  @instrumenter = instrumenter
  @name = "request.#{namespace}"
  @error_name = "error.#{namespace}"
end

Public Instance Methods

on_error(request, error) click to toggle source
# File lib/http/features/instrumentation.rb, line 43
def on_error(request, error)
  instrumenter.instrument(error_name, :request => request, :error => error)
end
wrap_request(request) click to toggle source
# File lib/http/features/instrumentation.rb, line 30
def wrap_request(request)
  # Emit a separate "start" event, so a logger can print the request
  # being run without waiting for a response
  instrumenter.instrument("start_#{name}", :request => request)
  instrumenter.start(name, :request => request)
  request
end
wrap_response(response) click to toggle source
# File lib/http/features/instrumentation.rb, line 38
def wrap_response(response)
  instrumenter.finish(name, :response => response)
  response
end