module NewRelic::Agent::Instrumentation::OpenAI::Chain

Public Class Methods

instrument!() click to toggle source
# File lib/new_relic/agent/instrumentation/ruby_openai/chain.rb, line 7
def self.instrument!
  ::OpenAI::Client.class_eval do
    include NewRelic::Agent::Instrumentation::OpenAI

    alias_method(:json_post_without_new_relic, :json_post)

    # In versions 4.0.0+ json_post is an instance method
    # defined in the OpenAI::HTTP module, included by the
    # OpenAI::Client class
    def json_post(**kwargs)
      json_post_with_new_relic(**kwargs) do
        json_post_without_new_relic(**kwargs)
      end
    end

    # In versions below 4.0.0 json_post is a class method
    # on OpenAI::Client
    class << self
      alias_method(:json_post_without_new_relic, :json_post)

      def json_post(**kwargs)
        json_post_with_new_relic(**kwargs) do
          json_post_without_new_relic(**kwargs)
        end
      end
    end
  end
end
json_post(**kwargs) click to toggle source
# File lib/new_relic/agent/instrumentation/ruby_openai/chain.rb, line 27
def json_post(**kwargs)
  json_post_with_new_relic(**kwargs) do
    json_post_without_new_relic(**kwargs)
  end
end
Also aliased as: json_post_without_new_relic
json_post_without_new_relic(**kwargs)
Alias for: json_post

Public Instance Methods

json_post(**kwargs) click to toggle source

In versions 4.0.0+ json_post is an instance method defined in the OpenAI::HTTP module, included by the OpenAI::Client class

# File lib/new_relic/agent/instrumentation/ruby_openai/chain.rb, line 16
def json_post(**kwargs)
  json_post_with_new_relic(**kwargs) do
    json_post_without_new_relic(**kwargs)
  end
end