module Atatus::Grape

Module for starting the Atatus agent and hooking into Grape.

Public Instance Methods

start(app, config = {}) click to toggle source

Start the Atatus agent and hook into Grape.

@param app [Grape::API] A Grape app. @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/grape.rb, line 32
def start(app, config = {})
  config = Config.new(config) unless config.is_a?(Config)
  configure_app(app, config)

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

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

Private Instance Methods

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

  agent.instrumenter.subscriber = Atatus::Subscriber.new(agent)
end
configure_app(app, config) click to toggle source
# File lib/atatus/grape.rb, line 48
def configure_app(app, config)
  config.service_name ||= app.name
  config.framework_name ||= 'Grape'
  config.framework_version ||= ::Grape::VERSION
  config.logger ||= app.logger
  config.__root_path ||= Dir.pwd
end