Module: NewRelic::Agent::Instrumentation::Parallel::Chain

Defined in:
lib/new_relic/agent/instrumentation/parallel/chain.rb

Class Method Summary collapse

Class Method Details

.instrument!Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/new_relic/agent/instrumentation/parallel/chain.rb', line 8

def self.instrument!
  ::Parallel.class_eval do
    class << self
      include NewRelic::Agent::Instrumentation::Parallel::Instrumentation

      alias_method :worker_without_newrelic, :worker

      def worker(job_factory, options, &block)
        return worker_without_newrelic(job_factory, options, &block) unless NewRelic::Agent.agent

        # Make sure the pipe channel listener is listening
        NewRelic::Agent::PipeChannelManager.listener.start unless NewRelic::Agent::PipeChannelManager.listener.started?

        # Create a unique id for the channel and register it
        channel_id = Process.clock_gettime(Process::CLOCK_MONOTONIC, :nanosecond)
        NewRelic::Agent.register_report_channel(channel_id)

        worker_without_newrelic(job_factory, options) do |*args|
          worker_with_tracing(channel_id) { yield(*args) }
        end
      end
    end
  end
end