Sha256: e6d4b291b705d95baa1f61b21e181c26a71678fd4f901422657cc198b9325f88

Contents?: true

Size: 1.39 KB

Versions: 3

Compression:

Stored size: 1.39 KB

Contents

require 'dependency_detection'
# This installs some code to manually start the agent when a delayed job worker starts.
# It's not really instrumentation.  It's more like a hook from DJ to RPM so it gets
# loaded at the time the RPM plugin initializes, which must be before the DJ worker
# initializes.  Loaded from control.rb
module NewRelic
  module DelayedJobInjection
    extend self
    attr_accessor :worker_name
  end
end

DependencyDetection.defer do
  depends_on do
    defined?(::Delayed) && defined?(::Delayed::Worker)
  end
  
  executes do
    Delayed::Worker.class_eval do
      def initialize_with_new_relic(*args)
        initialize_without_new_relic(*args)
        worker_name = case
                      when self.respond_to?(:name) then self.name
                      when self.class.respond_to?(:default_name) then self.class.default_name
                      end
        dispatcher_instance_id = worker_name || "host:#{Socket.gethostname} pid:#{Process.pid}" rescue "pid:#{Process.pid}"
        say "RPM Monitoring DJ worker #{dispatcher_instance_id}"
        NewRelic::DelayedJobInjection.worker_name = worker_name
        NewRelic::Control.instance.init_plugin :dispatcher => :delayed_job, :dispatcher_instance_id => dispatcher_instance_id
      end

      alias initialize_without_new_relic initialize
      alias initialize initialize_with_new_relic
    end
  end
end
DependencyDetection.detect!

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
newrelic_rpm-2.14.1.logging1 lib/new_relic/delayed_job_injection.rb
newrelic_rpm-2.14.1 lib/new_relic/delayed_job_injection.rb
newrelic_rpm-2.14.0 lib/new_relic/delayed_job_injection.rb