Class: VoyageAI::Instrumentation

Inherits:
Object
  • Object
show all
Defined in:
lib/voyageai/instrumentation.rb

Overview

Used for logging via HTTP.

Instance Method Summary collapse

Constructor Details

#initialize(logger:) ⇒ Instrumentation

Returns a new instance of Instrumentation.

Parameters:

  • logger (Logger)


7
8
9
# File 'lib/voyageai/instrumentation.rb', line 7

def initialize(logger:)
  @logger = logger
end

Instance Method Details

#finish(_, payload) ⇒ Object

Parameters:

  • payload (Hash)

Options Hash (payload):

  • :response (HTTP::Response)


30
31
32
33
# File 'lib/voyageai/instrumentation.rb', line 30

def finish(_, payload)
  response = payload[:response]
  @logger.info("#{response.status.code} #{response.status.reason}")
end

#instrument(name, payload = {}) ⇒ Object

Parameters:

  • name (String)
  • payload (Hash) (defaults to: {})

Options Hash (payload):

  • :error (Exception)


14
15
16
17
18
19
# File 'lib/voyageai/instrumentation.rb', line 14

def instrument(name, payload = {})
  error = payload[:error]
  return unless error

  @logger.error("#{name}: #{error.message}")
end

#start(_, payload) ⇒ Object

Parameters:

  • payload (Hash)

Options Hash (payload):

  • :request (HTTP::Request)


23
24
25
26
# File 'lib/voyageai/instrumentation.rb', line 23

def start(_, payload)
  request = payload[:request]
  @logger.info("#{request.verb.upcase} #{request.uri}")
end