Skip to content
Dave Anderson edited this page Jan 23, 2017 · 2 revisions

Sometimes it's useful to run arbitrary code inside the agent. The ScoutApm::Debug class lets us install callbacks.

For instance, to log a message each time the background worker runs, you could insert this into unicorn.rb:

after_fork do |server, worker|
  if defined?(ScoutApm::Agent) && defined?(ScoutApm::Debug)
    ScoutApm::Debug.instance.register_periodic_hook do
      ScoutApm::Agent.instance.logger.debug("Background worker ran")
    end
  end
end
Clone this wiki locally