Sha256: dbd3b0901fef47bac817bcc9864b46db3bc139aabae71dd11566662839ab0f46

Contents?: true

Size: 864 Bytes

Versions: 19

Compression:

Stored size: 864 Bytes

Contents

# frozen_string_literal: true

module OmniAI
  # Used for logging.
  class Instrumentation
    # @param logger [Logger]
    def initialize(logger:)
      @logger = logger
    end

    # @param name [String]
    # @param payload [Hash]
    # @option payload [Exception] :error
    def instrument(name, payload = {})
      error = payload[:error]
      return unless error

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

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

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

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
omniai-1.9.2 lib/omniai/instrumentation.rb
omniai-1.9.1 lib/omniai/instrumentation.rb
omniai-1.9.0 lib/omniai/instrumentation.rb
omniai-1.8.4 lib/omniai/instrumentation.rb
omniai-1.8.3 lib/omniai/instrumentation.rb
omniai-1.8.2 lib/omniai/instrumentation.rb
omniai-1.8.1 lib/omniai/instrumentation.rb
omniai-1.8.0 lib/omniai/instrumentation.rb
omniai-1.7.0 lib/omniai/instrumentation.rb
omniai-1.6.6 lib/omniai/instrumentation.rb
omniai-1.6.5 lib/omniai/instrumentation.rb
omniai-1.6.4 lib/omniai/instrumentation.rb
omniai-1.6.3 lib/omniai/instrumentation.rb
omniai-1.6.2 lib/omniai/instrumentation.rb
omniai-1.6.1 lib/omniai/instrumentation.rb
omniai-1.6.0 lib/omniai/instrumentation.rb
omniai-1.5.2 lib/omniai/instrumentation.rb
omniai-1.5.1 lib/omniai/instrumentation.rb
omniai-1.5.0 lib/omniai/instrumentation.rb