module OneApm module Agent class Agent module ForkableDispatcherFunctions def after_fork(options={}) needs_restart = false @after_fork_lock.synchronize do needs_restart = @harvester.needs_restart? @harvester.mark_started end return if !needs_restart || !Manager.config[:agent_enabled] || !Manager.config[:monitor_mode] || disconnected? OneApm::Manager.logger.debug "Starting the worker thread in #{Process.pid} (parent #{Process.ppid}) after forking." channel_id = options[:report_to_channel] install_pipe_service(channel_id) if channel_id reset_objects_with_locks drop_buffered_data setup_and_start_agent(options) end def install_pipe_service(channel_id) @service = OneApm::Agent::ForkedProcessService.new(channel_id) if connected? @connected_pid = Process.pid else OneApm::Manager.logger.debug("Child process #{Process.pid} not reporting to non-connected parent (process #{Process.ppid}).") @service.shutdown(Time.now) disconnect end end def synchronize_with_harvest harvest_lock.synchronize do yield end end def reset_objects_with_locks @stats_engine = OneApm::Collector::StatsEngine.new reset_harvest_locks end def reset_harvest_locks return if harvest_lock.nil? harvest_lock.unlock if harvest_lock.locked? end def flush_pipe_data if connected? && @service.is_a?(::OneApm::Agent::ForkedProcessService) transmit_data transmit_event_data end end end end end end