7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/new_relic/agent/instrumentation/ruby_kafka/chain.rb', line 7
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 ||
kwargs[: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
|