Class: VoyageAI::Instrumentation
- Inherits:
-
Object
- Object
- VoyageAI::Instrumentation
- Defined in:
- lib/voyageai/instrumentation.rb
Overview
Used for logging via HTTP.
Instance Method Summary collapse
- #finish(_, payload) ⇒ Object
-
#initialize(logger:) ⇒ Instrumentation
constructor
A new instance of Instrumentation.
- #instrument(name, payload = {}) ⇒ Object
- #start(_, payload) ⇒ Object
Constructor Details
#initialize(logger:) ⇒ Instrumentation
Returns a new instance of Instrumentation.
7 8 9 |
# File 'lib/voyageai/instrumentation.rb', line 7 def initialize(logger:) @logger = logger end |
Instance Method Details
#finish(_, payload) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/voyageai/instrumentation.rb', line 39 def finish(_, payload) response = payload[:response] return unless response @logger.info("#{response.status.code} #{response.status.reason}") end |
#instrument(name, payload = {}) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/voyageai/instrumentation.rb', line 15 def instrument(name, payload = {}) start(name, payload) yield(payload) if block_given? ensure finish(name, payload) end |
#start(_, payload) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/voyageai/instrumentation.rb', line 27 def start(_, payload) request = payload[:request] return unless request @logger.info("#{request.verb.upcase} #{request.uri}") end |