Sha256: 469f019f5e2fe5a4b13ff0691dfc9915707615b2517e3e8264fa037d45d16cd9
Contents?: true
Size: 1.39 KB
Versions: 1
Compression:
Stored size: 1.39 KB
Contents
# frozen_string_literal: true require 'elastic_apm/subscriber' require 'elastic_apm/normalizers/grape' module ElasticAPM # Module for starting the ElasticAPM agent and hooking into Grape. module Grape extend self # rubocop:disable Metrics/MethodLength, Metrics/AbcSize # Start the ElasticAPM 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. 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 # rubocop:enable Metrics/MethodLength, Metrics/AbcSize private 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 def attach_subscriber(agent) return unless agent agent.instrumenter.subscriber = ElasticAPM::Subscriber.new(agent) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
elastic-apm-3.2.0 | lib/elastic_apm/grape.rb |