module Tracebin::Agent

Attributes

config[RW]
logger[RW]
storage[RW]

Public Class Methods

child_process_started?() click to toggle source
# File lib/tracebin/agent.rb, line 83
def child_process_started?
  @child_process_started
end
configure() { |config| ... } click to toggle source
# File lib/tracebin/agent.rb, line 126
def self.configure
  yield config
end
init_logger() click to toggle source
# File lib/tracebin/agent.rb, line 87
def init_logger
  if defined? ::Rails
    @logger = ::Rails.logger
  else
    @logger ||= Logger.new(STDOUT)
    @logger.level = log_level
  end

  @logger
end
init_storage() click to toggle source
# File lib/tracebin/agent.rb, line 109
def init_storage
  @storage = ::Tracebin::Storage.new
end
log_level() click to toggle source
# File lib/tracebin/agent.rb, line 98
def log_level
  case config.log_level.downcase
  when 'debug' then Logger::DEBUG
  when 'info' then Logger::INFO
  when 'warn' then Logger::WARN
  when 'error' then Logger::ERROR
  when 'fatal' then Logger::FATAL
  else Logger::INFO
  end
end
parent_process_started?() click to toggle source
# File lib/tracebin/agent.rb, line 79
def parent_process_started?
  @parent_process_started
end
reset() click to toggle source
# File lib/tracebin/agent.rb, line 122
def self.reset
  @config = Config.new
end
start_child_process() click to toggle source
# File lib/tracebin/agent.rb, line 34
def start_child_process
  return if child_process_started? || !config.enabled

  logger.info "TRACEBIN: Starting Tracebin child process..."
  init_storage

  @child_process_reporter = Reporter.new
  @child_process_reporter.start!

  @child_process_started = true
  logger.info "TRACEBIN: Tracebin child process started!"
rescue => e
  logger.info "TRACEBIN: Error occurred while trying to start child process: #{e.message}"
end
start_parent_process() click to toggle source
# File lib/tracebin/agent.rb, line 15
def start_parent_process
  return if parent_process_started? || !config.enabled

  logger.info "TRACEBIN: Starting Tracebin parent process..."
  init_storage

  @subscribers = Subscribers.new
  @health_monitor = HealthMonitor.start
  @worker_process_monitor = WorkerProcessMonitor.start

  @parent_process_reporter = Reporter.new
  @parent_process_reporter.start!

  @parent_process_started = true
  logger.info "TRACEBIN: Tracebin parent process started!"
rescue => e
  logger.info "TRACEBIN: Error occurred while trying to start parent process: #{e.message}"
end
stop_child_processes() click to toggle source
# File lib/tracebin/agent.rb, line 65
def stop_child_processes
  return unless child_process_started?

  logger.info "TRACEBIN: Shutting down child process..."

  @child_process_reporter.stop!

  storage.unload

  @child_process_started = false

  logger.info "TRACEBIN: Child process stopped!"
end
stop_parent_process() click to toggle source
# File lib/tracebin/agent.rb, line 49
def stop_parent_process
  return unless parent_process_started?

  logger.info "TRACEBIN: Shutting down parent process..."

  @health_monitor.stop!
  @worker_process_monitor.stop!
  @parent_process_reporter.stop!

  storage.unload

  @parent_process_started = false

  logger.info "TRACEBIN: Parent process stopped!"
end