lib/elastic_apm/config.rb in elastic-apm-2.0.1 vs lib/elastic_apm/config.rb in elastic-apm-2.1.0
- old
+ new
@@ -1,14 +1,17 @@
# frozen_string_literal: true
require 'logger'
require 'yaml'
+require 'elastic_apm/util/prefixed_logger'
require 'elastic_apm/config/duration'
require 'elastic_apm/config/size'
module ElasticAPM
+ class ConfigError < StandardError; end
+
# rubocop:disable Metrics/ClassLength
# @api private
class Config
DEFAULTS = {
config_file: 'config/elastic_apm.yml',
@@ -142,23 +145,27 @@
attr_accessor :source_lines_span_library_frames
attr_accessor :transaction_max_spans
attr_accessor :transaction_sample_rate
attr_accessor :verify_server_cert
- attr_reader :custom_key_filters
- attr_reader :ignore_url_patterns
- attr_reader :span_frames_min_duration
- attr_reader :span_frames_min_duration_us
+ attr_reader :custom_key_filters
+ attr_reader :ignore_url_patterns
+ attr_reader :span_frames_min_duration
+ attr_reader :span_frames_min_duration_us
attr_accessor :view_paths
attr_accessor :root_path
alias :disable_send? :disable_send
alias :http_compression? :http_compression
alias :instrument? :instrument
alias :verify_server_cert? :verify_server_cert
+ def alert_logger
+ @alert_logger ||= PrefixedLogger.new($stdout, prefix: Logging::PREFIX)
+ end
+
def app=(app)
case app_type?(app)
when :sinatra
set_sinatra(app)
when :rails
@@ -196,10 +203,11 @@
def available_spies
%w[
action_dispatch
delayed_job
elasticsearch
+ faraday
http
json
mongo
net_http
redis
@@ -232,16 +240,26 @@
enabled_environments=
disable_environment_warning=
].freeze
def respond_to_missing?(name)
- DEPRECATED_OPTIONS.include? name
+ return true if DEPRECATED_OPTIONS.include? name
+ return true if name.to_s.end_with?('=')
+ false
end
def method_missing(name, *args)
- return super unless DEPRECATED_OPTIONS.include?(name)
- warn "The option `#{name}' has been removed."
+ if DEPRECATED_OPTIONS.include?(name)
+ alert_logger.warn "The option `#{name}' has been removed."
+ return
+ end
+
+ if name.to_s.end_with?('=')
+ raise ConfigError, "No such option `#{name.to_s.delete('=')}'"
+ end
+
+ super
end
private
def assign(options)
@@ -278,14 +296,24 @@
# rubocop:enable Metrics/AbcSize
# rubocop:enable Metrics/MethodLength, Metrics/CyclomaticComplexity
def set_from_args(options)
assign(options)
+ rescue ConfigError => e
+ alert_logger.warn format(
+ 'Failed to configure from arguments: %s',
+ e.message
+ )
end
def set_from_config_file
return unless File.exist?(config_file)
assign(YAML.load_file(config_file) || {})
+ rescue ConfigError => e
+ alert_logger.warn format(
+ 'Failed to configure from config file: %s',
+ e.message
+ )
end
def set_sinatra(app)
self.service_name = format_name(service_name || app.to_s)
self.framework_name = framework_name || 'Sinatra'