Sha256: da649b3b2254462e95117d12acc89adf0608ae18568547325633476e428aca50

Contents?: true

Size: 1.1 KB

Versions: 13

Compression:

Stored size: 1.1 KB

Contents

# This file is distributed under New Relic's license terms.
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
# frozen_string_literal: true

module NewRelic::Agent::Instrumentation
  module OpenAI::Chain
    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
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
newrelic_rpm-9.17.0 lib/new_relic/agent/instrumentation/ruby_openai/chain.rb
newrelic_rpm-9.16.1 lib/new_relic/agent/instrumentation/ruby_openai/chain.rb
newrelic_rpm-9.16.0 lib/new_relic/agent/instrumentation/ruby_openai/chain.rb
newrelic_rpm-9.15.0 lib/new_relic/agent/instrumentation/ruby_openai/chain.rb
newrelic_rpm-9.14.0 lib/new_relic/agent/instrumentation/ruby_openai/chain.rb
newrelic_rpm-9.13.0 lib/new_relic/agent/instrumentation/ruby_openai/chain.rb
newrelic_rpm-9.12.0 lib/new_relic/agent/instrumentation/ruby_openai/chain.rb
newrelic_rpm-9.11.0 lib/new_relic/agent/instrumentation/ruby_openai/chain.rb
newrelic_rpm-9.10.2 lib/new_relic/agent/instrumentation/ruby_openai/chain.rb
newrelic_rpm-9.10.1 lib/new_relic/agent/instrumentation/ruby_openai/chain.rb
newrelic_rpm-9.10.0 lib/new_relic/agent/instrumentation/ruby_openai/chain.rb
newrelic_rpm-9.9.0 lib/new_relic/agent/instrumentation/ruby_openai/chain.rb
newrelic_rpm-9.8.0 lib/new_relic/agent/instrumentation/ruby_openai/chain.rb