Class: Atatus::Spies::SidekiqSpy Private

Inherits:
Object
  • Object
show all
Defined in:
lib/atatus/spies/sidekiq.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Defined Under Namespace

Classes: Middleware

Constant Summary collapse

ACTIVE_JOB_WRAPPER =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

'ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.name_for(job) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



47
48
49
50
51
52
53
54
55
56
# File 'lib/atatus/spies/sidekiq.rb', line 47

def self.name_for(job)
  klass = job['class']

  case klass
  when ACTIVE_JOB_WRAPPER
    job['wrapped']
  else
    klass
  end
end

Instance Method Details

#installObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



102
103
104
105
# File 'lib/atatus/spies/sidekiq.rb', line 102

def install
  install_processor
  install_middleware
end

#install_middlewareObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/atatus/spies/sidekiq.rb', line 58

def install_middleware
  if defined?(::Sidekiq)

    Sidekiq.configure_server do |config|
      config.server_middleware do |chain|
        chain.add Middleware
      end
    end

  end
end

#install_processorObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/atatus/spies/sidekiq.rb', line 70

def install_processor
  require 'sidekiq/processor'

  if defined?(::Sidekiq) && defined?(::Sidekiq::Processor)

    Sidekiq::Processor.class_eval do
      alias start_without_apm start
      alias terminate_without_apm terminate

      def start
        result = start_without_apm

        # Already running from Railtie if Rails
        if Atatus.running?
          Atatus.agent.config.logger = Sidekiq.logger
        else
          Atatus.start
        end

        result
      end

      def terminate
        terminate_without_apm

        Atatus.stop
      end
    end

  end
end