Class: HTTP::Features::Instrumentation

Inherits:
Object
  • Object
show all
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) .get("https://example.com/")

Defined Under Namespace

Classes: NullInstrumenter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(instrumenter: NullInstrumenter.new, namespace: "http") ⇒ Instrumentation

Returns a new instance of Instrumentation.



18
19
20
21
# File 'lib/http/features/instrumentation.rb', line 18

def initialize(instrumenter: NullInstrumenter.new, namespace: "http")
  @instrumenter = instrumenter
  @name = "request.#{namespace}"
end

Instance Attribute Details

#instrumenterObject (readonly)

Returns the value of attribute instrumenter.



16
17
18
# File 'lib/http/features/instrumentation.rb', line 16

def instrumenter
  @instrumenter
end

#nameObject (readonly)

Returns the value of attribute name.



16
17
18
# File 'lib/http/features/instrumentation.rb', line 16

def name
  @name
end

Instance Method Details

#wrap_request(request) ⇒ Object



23
24
25
26
27
# File 'lib/http/features/instrumentation.rb', line 23

def wrap_request(request)
  instrumenter.instrument("start_#{name}", :request => request)
  instrumenter.start(name, :request => request)
  request
end

#wrap_response(response) ⇒ Object



29
30
31
32
# File 'lib/http/features/instrumentation.rb', line 29

def wrap_response(response)
  instrumenter.finish(name, :response => response)
  response
end