Sha256: 75a160c127029a20466fffa26a12a88e734988d7f34b1cbae0e61b3dc4d259ee

Contents?: true

Size: 1.78 KB

Versions: 39

Compression:

Stored size: 1.78 KB

Contents

# encoding: utf-8

LibraryDetection.defer do
  @name = :sidekiq

  depends_on do
    defined?(::Sidekiq) && !OneApm::Manager.config[:disable_sidekiq]
  end

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

  executes do
    class OneApm::SidekiqInstrumentation
      include OneApm::Agent::Instrumentation::TransactionBase

      # Client middleware has additional parameters, and our tests use the
      # middleware client-side to work inline.
      def call(worker, msg, queue, *_)
        trace_args = if worker.respond_to?(:oneapm_trace_args)
          worker.oneapm_trace_args(msg, queue)
        else
          self.class.default_trace_args(msg)
        end

        perform_action_with_oneapm_trace(trace_args) do
          if OneApm::Manager.config[:'sidekiq.capture_params']
            OneApm::Manager.add_custom_parameters(:job_arguments => msg['args'])
          end
          yield
        end
      end

      def self.default_trace_args(msg)
        {
          :name => 'perform',
          :class_name => msg['class'],
          :category => 'OtherTransaction/SidekiqJob'
        }
      end
    end

    class Sidekiq::Extensions::DelayedClass
      def oneapm_trace_args(msg, queue)
        (target, method_name, _args) = YAML.load(msg['args'][0])
        {
          :name => method_name,
          :class_name => target.name,
          :category => 'OtherTransaction/SidekiqJob'
        }
      rescue => e
        OneApm::Manager.logger.error("Failure during deserializing YAML for Sidekiq::Extensions::DelayedClass", e)
        OneApm::SidekiqInstrumentation.default_trace_args(msg)
      end
    end

    Sidekiq.configure_server do |config|
      config.server_middleware do |chain|
        chain.add OneApm::SidekiqInstrumentation
      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/sidekiq.rb
oneapm_rpm-1.4.1 lib/one_apm/inst/background_job/sidekiq.rb
oneapm_rpm-1.4.0 lib/one_apm/inst/background_job/sidekiq.rb
oneapm_rpm-1.3.7 lib/one_apm/inst/background_job/sidekiq.rb
oneapm_rpm-1.3.7.rc1 lib/one_apm/inst/background_job/sidekiq.rb
oneapm_rpm-1.3.6 lib/one_apm/inst/background_job/sidekiq.rb
oneapm_rpm-1.3.6.rc1 lib/one_apm/inst/background_job/sidekiq.rb
oneapm_rpm-1.3.5 lib/one_apm/inst/background_job/sidekiq.rb
oneapm_rpm-1.3.5.rc1 lib/one_apm/inst/background_job/sidekiq.rb
oneapm_rpm-1.3.4 lib/one_apm/inst/background_job/sidekiq.rb
oneapm_rpm-1.3.4.rc1 lib/one_apm/inst/background_job/sidekiq.rb
oneapm_rpm-1.3.3 lib/one_apm/inst/background_job/sidekiq.rb
oneapm_rpm-1.3.3.rc1 lib/one_apm/inst/background_job/sidekiq.rb
oneapm_rpm-1.3.2 lib/one_apm/inst/background_job/sidekiq.rb
oneapm_rpm-1.3.2.rc1 lib/one_apm/inst/background_job/sidekiq.rb
oneapm_rpm-1.3.1 lib/one_apm/inst/background_job/sidekiq.rb
oneapm_rpm-1.3.1.rc1 lib/one_apm/inst/background_job/sidekiq.rb
oneapm_rpm-1.3.0 lib/one_apm/inst/background_job/sidekiq.rb
oneapm_rpm-1.3.0.rc1 lib/one_apm/inst/background_job/sidekiq.rb
oneapm_rpm-1.2.9 lib/one_apm/inst/background_job/sidekiq.rb