Sha256: 18d2d826b21d762756d2c443c3d206e211c383743adc95c2add1ee6ed22149e4

Contents?: true

Size: 1.7 KB

Versions: 13

Compression:

Stored size: 1.7 KB

Contents

module Instana
  module Instrumentation
    class SidekiqWorker
      def call(_worker, msg, _queue)
        kv_payload = { :'sidekiq-worker' => {} }
        kv_payload[:'sidekiq-worker'][:job_id] = msg['jid']
        kv_payload[:'sidekiq-worker'][:queue] = msg['queue']
        kv_payload[:'sidekiq-worker'][:job] = msg['class']
        kv_payload[:'sidekiq-worker'][:retry] = msg['retry'].to_s

        # Temporary until we move connection collection to redis
        # instrumentation
        Sidekiq.redis_pool.with do |client|
          opts = client.respond_to?(:connection) ? client.connection : client.client.options
          kv_payload[:'sidekiq-worker'][:'redis-url'] = "#{opts[:host]}:#{opts[:port]}"
        end

        context = {}
        if msg.key?('X-Instana-T')
          trace_id = msg.delete('X-Instana-T')
          span_id = msg.delete('X-Instana-S')
          context[:trace_id] = ::Instana::Util.header_to_id(trace_id)
          context[:span_id] = ::Instana::Util.header_to_id(span_id) if span_id
        end

        ::Instana.tracer.log_start_or_continue(
          :'sidekiq-worker', kv_payload, context
        )

        yield
      rescue => e
        kv_payload[:'sidekiq-worker'][:error] = true
        ::Instana.tracer.log_info(kv_payload)
        ::Instana.tracer.log_error(e)
        raise
      ensure
        ::Instana.tracer.log_end(:'sidekiq-worker', {}) if ::Instana.tracer.tracing?
      end
    end
  end
end

if defined?(::Sidekiq) && ::Instana.config[:'sidekiq-worker'][:enabled]
  ::Sidekiq.configure_server do |cfg|
    cfg.server_middleware do |chain|
      ::Instana.logger.info "Instrumenting Sidekiq worker"
      chain.add ::Instana::Instrumentation::SidekiqWorker
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
instana-1.9.0 lib/instana/instrumentation/sidekiq-worker.rb
instana-1.9.0.daftrabbit lib/instana/instrumentation/sidekiq-worker.rb
instana-1.8.3 lib/instana/instrumentation/sidekiq-worker.rb
instana-1.9.0.sillyrabbit lib/instana/instrumentation/sidekiq-worker.rb
instana-1.8.2 lib/instana/instrumentation/sidekiq-worker.rb
instana-1.8.1 lib/instana/instrumentation/sidekiq-worker.rb
instana-1.8.0 lib/instana/instrumentation/sidekiq-worker.rb
instana-1.7.15 lib/instana/instrumentation/sidekiq-worker.rb
instana-1.7.14 lib/instana/instrumentation/sidekiq-worker.rb
instana-1.7.14a lib/instana/instrumentation/sidekiq-worker.rb
instana-1.7.13 lib/instana/instrumentation/sidekiq-worker.rb
instana-1.7.12 lib/instana/instrumentation/sidekiq-worker.rb
instana-1.7.11 lib/instana/instrumentation/sidekiq-worker.rb