Class: HTTP::Features::Instrumentation
- Inherits:
-
HTTP::Feature
- Object
- HTTP::Feature
- HTTP::Features::Instrumentation
- Defined in:
- lib/http/features/instrumentation.rb
Overview
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: 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 startedrequest.http
after the response is recieved, and containsstart
andfinish
so the duration of the request can be calculated.
Defined Under Namespace
Classes: NullInstrumenter
Instance Attribute Summary collapse
-
#error_name ⇒ Object
readonly
Returns the value of attribute error_name.
-
#instrumenter ⇒ Object
readonly
Returns the value of attribute instrumenter.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(instrumenter: NullInstrumenter.new, namespace: "http") ⇒ Instrumentation
constructor
A new instance of Instrumentation.
- #on_error(request, error) ⇒ Object
- #wrap_request(request) ⇒ Object
- #wrap_response(response) ⇒ Object
Constructor Details
#initialize(instrumenter: NullInstrumenter.new, namespace: "http") ⇒ Instrumentation
Returns a new instance of Instrumentation.
24 25 26 27 28 29 |
# File 'lib/http/features/instrumentation.rb', line 24 def initialize(instrumenter: NullInstrumenter.new, namespace: "http") super() @instrumenter = instrumenter @name = "request.#{namespace}" @error_name = "error.#{namespace}" end |
Instance Attribute Details
#error_name ⇒ Object (readonly)
Returns the value of attribute error_name.
22 23 24 |
# File 'lib/http/features/instrumentation.rb', line 22 def error_name @error_name end |
#instrumenter ⇒ Object (readonly)
Returns the value of attribute instrumenter.
22 23 24 |
# File 'lib/http/features/instrumentation.rb', line 22 def instrumenter @instrumenter end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
22 23 24 |
# File 'lib/http/features/instrumentation.rb', line 22 def name @name end |
Instance Method Details
#on_error(request, error) ⇒ Object
44 45 46 |
# File 'lib/http/features/instrumentation.rb', line 44 def on_error(request, error) instrumenter.instrument(error_name, request: request, error: error) end |
#wrap_request(request) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/http/features/instrumentation.rb', line 31 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) ⇒ Object
39 40 41 42 |
# File 'lib/http/features/instrumentation.rb', line 39 def wrap_response(response) instrumenter.finish(name, response: response) response end |