Sha256: a19a0fdf8556f9f6ca886e604fc7a676f4117d437b96c73d208421a8440e83de

Contents?: true

Size: 1.61 KB

Versions: 5

Compression:

Stored size: 1.61 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 'new_relic/agent/instrumentation/controller_instrumentation'

DependencyDetection.defer do
  @name = :delayed_job
  
  depends_on do
    !NewRelic::Agent.config[:disable_dj]
  end

  depends_on do
    # double check because of old JRuby bug 
    defined?(::Delayed) && defined?(::Delayed::Job) &&
      Delayed::Job.method_defined?(:invoke_job)
  end
  
  executes do
    ::NewRelic::Agent.logger.info 'Installing DelayedJob instrumentation'
  end
  
  executes do
    Delayed::Job.class_eval do
      include NewRelic::Agent::Instrumentation::ControllerInstrumentation
      if self.instance_methods.include?('name') || self.instance_methods.include?(:name)
        add_transaction_tracer "invoke_job", :category => 'OtherTransaction/DelayedJob', :path => '#{self.name}'
      else
        add_transaction_tracer "invoke_job", :category => 'OtherTransaction/DelayedJob'
      end
    end
  end

  executes do
    Delayed::Job.instance_eval do
      if self.respond_to?('after_fork')
        if method_defined?(:after_fork)
          def after_fork_with_newrelic
            NewRelic::Agent.after_fork(:force_reconnect => true)
            after_fork_without_newrelic
          end

          alias_method :after_fork_without_newrelic, :after_fork
          alias_method :after_fork, :after_fork_with_newrelic
        else
          def after_fork
            NewRelic::Agent.after_fork(:force_reconnect => true)
            super
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
newrelic_rpm-3.6.1.86.beta lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb
newrelic_rpm-3.6.1.85.beta lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb
newrelic_rpm-3.6.0.83 lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb
newrelic_rpm-3.6.0.78 lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb
newrelic_rpm-3.6.0.74.beta lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb