Sha256: 44bd55e6f24d2769727997b7aafc8db5d30da787a72cf6e51395e0b557189a6d

Contents?: true

Size: 1.67 KB

Versions: 39

Compression:

Stored size: 1.67 KB

Contents

# encoding: utf-8

LibraryDetection.defer do
  @name = :delayed_job

  depends_on do
    !OneApm::Manager.config[:disable_dj]
  end

  depends_on do
    defined?(::Delayed) && defined?(::Delayed::Worker) && !OneApm::Manager.config[:disable_dj]
  end

  executes do
    OneApm::Manager.logger.info 'Installing DelayedJob instrumentation'
  end

  executes do
    Delayed::Worker.class_eval do
      def initialize_with_one_apm(*args)
        initialize_without_one_apm(*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
        OneApm::DelayedJobInjection.worker_name = worker_name

        if defined?(::Delayed::Job) && ::Delayed::Job.method_defined?(:invoke_job)
          install_oneapm_job_tracer
          OneApm::Probe.instance.init_plugin :dispatcher => :delayed_job
        else
          OneApm::Manager.logger.warn("Did not find a Delayed::Job class responding to invoke_job, aborting DJ instrumentation")
        end
      end

      alias initialize_without_one_apm initialize
      alias initialize initialize_with_one_apm

      def install_oneapm_job_tracer
        Delayed::Job.class_eval do
          include OneApm::Agent::Instrumentation::TransactionBase
          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
    end
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
oneapm_rpm-1.4.2 lib/one_apm/inst/background_job/delayed_job.rb
oneapm_rpm-1.4.1 lib/one_apm/inst/background_job/delayed_job.rb
oneapm_rpm-1.4.0 lib/one_apm/inst/background_job/delayed_job.rb
oneapm_rpm-1.3.7 lib/one_apm/inst/background_job/delayed_job.rb
oneapm_rpm-1.3.7.rc1 lib/one_apm/inst/background_job/delayed_job.rb
oneapm_rpm-1.3.6 lib/one_apm/inst/background_job/delayed_job.rb
oneapm_rpm-1.3.6.rc1 lib/one_apm/inst/background_job/delayed_job.rb
oneapm_rpm-1.3.5 lib/one_apm/inst/background_job/delayed_job.rb
oneapm_rpm-1.3.5.rc1 lib/one_apm/inst/background_job/delayed_job.rb
oneapm_rpm-1.3.4 lib/one_apm/inst/background_job/delayed_job.rb
oneapm_rpm-1.3.4.rc1 lib/one_apm/inst/background_job/delayed_job.rb
oneapm_rpm-1.3.3 lib/one_apm/inst/background_job/delayed_job.rb
oneapm_rpm-1.3.3.rc1 lib/one_apm/inst/background_job/delayed_job.rb
oneapm_rpm-1.3.2 lib/one_apm/inst/background_job/delayed_job.rb
oneapm_rpm-1.3.2.rc1 lib/one_apm/inst/background_job/delayed_job.rb
oneapm_rpm-1.3.1 lib/one_apm/inst/background_job/delayed_job.rb
oneapm_rpm-1.3.1.rc1 lib/one_apm/inst/background_job/delayed_job.rb
oneapm_rpm-1.3.0 lib/one_apm/inst/background_job/delayed_job.rb
oneapm_rpm-1.3.0.rc1 lib/one_apm/inst/background_job/delayed_job.rb
oneapm_rpm-1.2.9 lib/one_apm/inst/background_job/delayed_job.rb