module Atatus::Rails

Module for explicitly starting the Atatus agent and hooking into Rails. It is recommended to use the Railtie instead.

Public Instance Methods

start(config) click to toggle source

Start the Atatus agent and hook into Rails. Note that the agent won't be started if the Rails console is being used.

@param config [Config, Hash] An instance of Config or a Hash config. @return [true, nil] true if the agent was started, nil otherwise.

# File lib/atatus/rails.rb, line 34
def start(config)
  config = Config.new(config) unless config.is_a?(Config)

  if (reason = should_skip?(config))
    unless config.disable_start_message?
      config.logger.info "Skipping because: #{reason}. " \
        "Start manually with `Atatus.start'"
    end

    return
  end

  Atatus.start(config).tap do |agent|
    attach_subscriber(agent)
  end

  Atatus.running?
rescue StandardError => e
  if config.disable_start_message?
    config.logger.error format('Failed to start: %s', e.message)
    config.logger.error "Backtrace:\n" + e.backtrace.join("\n")
  else
    puts format('Failed to start: %s', e.message)
    puts "Backtrace:\n" + e.backtrace.join("\n")
  end
end

Private Instance Methods

attach_subscriber(agent) click to toggle source
# File lib/atatus/rails.rb, line 71
def attach_subscriber(agent)
  return unless agent

  agent.instrumenter.subscriber = Atatus::Subscriber.new(agent)
end
should_skip?(_config) click to toggle source
# File lib/atatus/rails.rb, line 63
def should_skip?(_config)
  if ::Rails.const_defined?('Console', false)
    return 'Rails console'
  end

  nil
end