lib/contrast/agent/at_exit_hook.rb in contrast-agent-3.10.2 vs lib/contrast/agent/at_exit_hook.rb in contrast-agent-3.11.0

- old
+ new

@@ -6,28 +6,31 @@ module Contrast module Agent # This module adds an at_exit hook for us to send messages that may be lost at process exit module AtExitHook include Contrast::Components::Interface - access_component :logging, :contrast_service - - TERMINATION_NOTICE = 'at_exit invoked, host application terminating' - + access_component :contrast_service, :logging def self.exit_hook @_exit_hook ||= begin at_exit do - logger.debug(TERMINATION_NOTICE) - - context = Contrast::Agent::REQUEST_TRACKER.current - CONTRAST_SERVICE.send_message(context.activity) if context - - logger.debug(" - current PID #{ @pid }") - logger.debug(" - current PPID #{ @ppid }") - logger.debug(" - process PID #{ Process.pid }") - logger.debug(" - process PPID #{ Process.ppid }") + on_exit end true end + end + + # Actions to take when a process exits. Typically called from our + # exit_hook, but exposed here for other process terminations, like those + # in Kernel#exec + def self.on_exit + logger.debug('at_exit invoked, host application terminating', + p_id: @pid, + pp_id: @ppid, + process_pid: Process.pid, + process_pp_id: Process.ppid) + + context = Contrast::Agent::REQUEST_TRACKER.current + CONTRAST_SERVICE.send_message(context.activity) if context end end end end