Module: ElasticAPM::Grape

Extended by:
Grape
Included in:
Grape
Defined in:
lib/elastic_apm/grape.rb

Overview

Module for starting the ElasticAPM agent and hooking into Grape.

Instance Method Summary collapse

Instance Method Details

#start(app, config = {}) ⇒ true?

Start the ElasticAPM agent and hook into Grape.

Parameters:

  • app (Grape::API)

    A Grape app.

  • config (Config, Hash) (defaults to: {})

    An instance of Config or a Hash config.

Returns:

  • (true, nil)

    true if the agent was started, nil otherwise.



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/elastic_apm/grape.rb', line 32

def start(app, config = {})
  config = Config.new(config) unless config.is_a?(Config)
  configure_app(app, config)

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

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