Module: ElasticAPM::Rails

Extended by:
Rails
Included in:
Rails
Defined in:
lib/elastic_apm/rails.rb

Overview

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

Instance Method Summary collapse

Instance Method Details

#start(config) ⇒ true?

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

Parameters:

  • config (Config, Hash)

    An instance of Config or a Hash config.

Returns:

  • (true, nil)

    true if the agent was started, nil otherwise.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/elastic_apm/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 `ElasticAPM.start'"
    end

    return
  end

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

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