# encoding: utf-8 LibraryDetection.defer do @name = :resque depends_on do defined?(::Resque::Job) && !OneApm::Manager.config[:disable_resque] && !OneApm::LanguageSupport.using_version?('1.9.1') end executes do OneApm::Manager.logger.info 'Installing Resque instrumentation' end executes do module Resque module Plugins module OneApmInstrumentation include OneApm::Agent::Instrumentation::TransactionBase def around_perform_with_monitoring(*args) begin perform_action_with_oneapm_trace( :name => 'perform', :class_name => self.name, :category => 'OtherTransaction/ResqueJob') do if OneApm::Manager.config[:'resque.capture_params'] OneApm::Manager.add_custom_parameters(:job_arguments => args) end yield(*args) end ensure OneApm::Manager.agent.flush_pipe_data end end end end end module OneApm module Agent module Instrumentation module ResqueInstrumentationInstaller def payload_class klass = super klass.instance_eval do extend ::Resque::Plugins::OneApmInstrumentation end end end end end end ::Resque::Job.class_eval do def self.new(*args) super(*args).extend OneApm::Agent::Instrumentation::ResqueInstrumentationInstaller end end if OneApm::LanguageSupport.can_fork? # Resque::Worker#fork isn't around in Resque 2.x if OneApm::VersionNumber.new(::Resque::VERSION) < OneApm::VersionNumber.new("2.0.0") ::Resque::Worker.class_eval do if OneApm::Manager.config[:'resque.use_harvest_lock'] OneApm::Manager.logger.info 'Installing Resque harvest/fork synchronization' def fork_with_oneapm(*args, &block) OneApm::Manager.agent.synchronize_with_harvest do fork_without_oneapm(*args, &block) # Reached in parent, not expected in the child since Resque # uses the block form of fork end end alias_method :fork_without_oneapm, :fork alias_method :fork, :fork_with_oneapm end end end ::Resque.before_first_fork do OneApm::Manager.start(:dispatcher => :resque, :sync_startup => true, :start_channel_listener => true) end ::Resque.before_fork do |job| if ENV['FORK_PER_JOB'] != 'false' OneApm::Support::ForkedProcessChannel.register_report_channel(job.object_id) end end ::Resque.after_fork do |job| # Only suppress reporting Instance/Busy for forked children # Traced errors UI relies on having the parent process report that metric OneApm::Manager.agent.after_fork(:report_to_channel => job.object_id, :report_instance_busy => false) end end end end # call this now so it is memoized before potentially forking worker processes OneApm::LanguageSupport.can_fork?