Sha256: 6ebfff7a51e7e332f701115223188c6c89ee4bd9131706cc6b8867cdd2a03d0c

Contents?: true

Size: 1.87 KB

Versions: 12

Compression:

Stored size: 1.87 KB

Contents

# encoding: utf-8
# This file is distributed under New Relic's license terms.
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.

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 the Ruby Agent so it gets loaded at the time the
# Ruby Agent 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
  @name = :delayed_job_injection
  
  depends_on do
    defined?(::Delayed) && defined?(::Delayed::Worker) && !NewRelic::Agent.config[:disable_dj]
  end
  
  executes do
    if NewRelic::Agent.respond_to?(:logger)
      ::NewRelic::Agent.logger.info 'Installing DelayedJob instrumentation hooks'
    end
  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 "New Relic Ruby Agent 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
        NewRelic::Agent.instance.add_harvest_sampler(NewRelic::Agent::Samplers::DelayedJobSampler)
      end

      alias initialize_without_new_relic initialize
      alias initialize initialize_with_new_relic
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
newrelic_rpm-3.6.5.130 lib/new_relic/delayed_job_injection.rb
newrelic_rpm-3.6.4.122 lib/new_relic/delayed_job_injection.rb
newrelic_rpm-3.6.4.113.beta lib/new_relic/delayed_job_injection.rb
newrelic_rpm-3.6.3.111 lib/new_relic/delayed_job_injection.rb
newrelic_rpm-3.6.3.106 lib/new_relic/delayed_job_injection.rb
newrelic_rpm-3.6.3.105.beta lib/new_relic/delayed_job_injection.rb
newrelic_rpm-3.6.3.104 lib/new_relic/delayed_job_injection.rb
newrelic_rpm-3.6.3.103.beta lib/new_relic/delayed_job_injection.rb
newrelic_rpm-3.6.2.96 lib/new_relic/delayed_job_injection.rb
newrelic_rpm-3.6.2.90.beta lib/new_relic/delayed_job_injection.rb
newrelic_rpm-3.6.1.88 lib/new_relic/delayed_job_injection.rb
newrelic_rpm-3.6.1.87 lib/new_relic/delayed_job_injection.rb