Sha256: 68ad7f581a1bf944b476dcfe89621f9987549bde847cad7fea046b026b9a07ed

Contents?: true

Size: 1.59 KB

Versions: 5

Compression:

Stored size: 1.59 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 RubyKafka::Chain
    def self.instrument!
      ::Kafka::Producer.class_eval do
        include NewRelic::Agent::Instrumentation::RubyKafka

        alias_method(:produce_without_new_relic, :produce)

        def produce(value, **kwargs)
          produce_with_new_relic(value, **kwargs) do |headers|
            kwargs[:headers] = headers
            produce_without_new_relic(value, **kwargs)
          end
        end
      end

      ::Kafka::Consumer.class_eval do
        include NewRelic::Agent::Instrumentation::RubyKafka

        alias_method(:each_message_without_new_relic, :each_message)

        def each_message(*args)
          each_message_without_new_relic(*args) do |message|
            each_message_with_new_relic(message) do
              yield(message)
            end
          end
        end
      end

      ::Kafka::Client.class_eval do
        include NewRelic::Agent::Instrumentation::RubyKafkaConfig

        alias_method(:producer_without_new_relic, :producer)
        alias_method(:consumer_without_new_relic, :consumer)

        def producer(**kwargs)
          producer_without_new_relic(**kwargs).tap do |producer|
            set_nr_config(producer)
          end
        end

        def consumer(**kwargs)
          consumer_without_new_relic(**kwargs).tap do |consumer|
            set_nr_config(consumer)
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
newrelic_rpm-9.17.0 lib/new_relic/agent/instrumentation/ruby_kafka/chain.rb
newrelic_rpm-9.16.1 lib/new_relic/agent/instrumentation/ruby_kafka/chain.rb
newrelic_rpm-9.16.0 lib/new_relic/agent/instrumentation/ruby_kafka/chain.rb
newrelic_rpm-9.15.0 lib/new_relic/agent/instrumentation/ruby_kafka/chain.rb
newrelic_rpm-9.14.0 lib/new_relic/agent/instrumentation/ruby_kafka/chain.rb