Skip to content

Commit

Permalink
separate remote client to before_perform, change resque_debug logs to…
Browse files Browse the repository at this point in the history
… debug level
  • Loading branch information
Mitch Hartweg committed Dec 12, 2024
1 parent 5e25d12 commit 3d7a90d
Showing 1 changed file with 9 additions and 34 deletions.
43 changes: 9 additions & 34 deletions lib/scout_apm/instruments/resque.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,17 @@ def config
@config || ScoutApm::Agent.instance.context.config
end

# Insert ourselves into the point when resque turns a string "TestJob"
# into the class constant TestJob, and insert our instrumentation plugin
# into that constantized class
#
# This automates away any need for the user to insert our instrumentation into
# each of their jobs
# def inject_job_instrument
# ::Resque::Job.class_eval do
# def payload_class_with_scout_instruments
# klass = payload_class_without_scout_instruments
# klass.extend(ScoutApm::Instruments::Resque)
# klass
# end
# alias_method :payload_class_without_scout_instruments, :payload_class
# alias_method :payload_class, :payload_class_with_scout_instruments
# end
# end

# def before_perform_scout_instrument(*args)
# ScoutApm::Agent.instance.context.logger.info "resque_debug IN BEFORE PERFORM"
# begin
# ScoutApm::Agent.instance.context.become_remote_client!(bind, port)
# # inject_job_instrument
# rescue => e
# ScoutApm::Agent.instance.context.logger.warn "Error while Installing Resque before_perform: #{e.inspect}"
# end
# end

def logger
ScoutApm::Agent.instance.context.logger
end

def around_perform_with_scout_instruments(*args)
logger.info "resque_debug IN AROUND PERFORM"
def before_perform_become_client(*args)
ScoutApm::Agent.instance.context.become_remote_client!(bind, port)
logger.info "resque_debug REMOTE AGENT"
logger.debug "resque_debug REMOTE AGENT"
end

def around_perform_with_scout_instruments(*args)
logger.debug "resque_debug IN AROUND PERFORM"
job_name = self.to_s
queue = find_queue

Expand All @@ -57,7 +32,7 @@ def around_perform_with_scout_instruments(*args)
queue = args.first["queue_name"] rescue queue_name
end

logger.info "resque_debug JOB: #{job_name} QUEUE: #{queue}"
logger.debug "resque_debug JOB: #{job_name} QUEUE: #{queue}"

req = ScoutApm::RequestManager.lookup

Expand All @@ -69,14 +44,14 @@ def around_perform_with_scout_instruments(*args)
req.start_layer(ScoutApm::Layer.new('Job', job_name))
started_job = true

logger.info "resque_debug DOING LAYERS"
logger.debug "resque_debug DOING LAYERS"

yield
rescue => e
req.error!
raise
ensure
logger.info "resque_debug ENSURING"
logger.debug "resque_debug ENSURING"
req.stop_layer if started_job
req.stop_layer if started_queue
end
Expand Down

0 comments on commit 3d7a90d

Please sign in to comment.