lib/elastic_apm/config.rb in elastic-apm-2.10.0 vs lib/elastic_apm/config.rb in elastic-apm-2.10.1

- old
+ new

@@ -28,13 +28,13 @@ enabled_environments= disable_environment_warning= ].freeze # rubocop:disable Metrics/LineLength, Layout/ExtraSpacing - option :config_file, default: 'config/elastic_apm.yml' - option :server_url, default: 'http://localhost:8200' - option :secret_token + option :config_file, type: :string, default: 'config/elastic_apm.yml' + option :server_url, type: :string, default: 'http://localhost:8200' + option :secret_token, type: :string option :active, type: :bool, default: true option :api_buffer_size, type: :int, default: 256 option :api_request_size, type: :bytes, default: '750kb', converter: Bytes.new option :api_request_time, type: :float, default: '10s', converter: Duration.new @@ -81,26 +81,36 @@ option :transaction_max_spans, type: :int, default: 500 option :transaction_sample_rate, type: :float, default: 1.0 option :verify_server_cert, type: :bool, default: true # rubocop:enable Metrics/LineLength, Layout/ExtraSpacing + # rubocop:disable Metrics/MethodLength def initialize(options = {}) @options = load_schema custom_logger = options.delete(:logger) assign(options) + + # Pick out config_file specifically as we need it now to load it, + # but still need the other env vars to have precedence + env = load_env + if (env_config_file = env.delete(:config_file)) + self.config_file = env_config_file + end + assign(load_config_file) - assign(load_env) + assign(env) yield self if block_given? @logger = custom_logger || build_logger @__view_paths = [] @__root_path = Dir.pwd end + # rubocop:enable Metrics/MethodLength attr_accessor :__view_paths, :__root_path attr_accessor :logger attr_reader :options @@ -203,11 +213,12 @@ private def load_config_file return unless File.exist?(config_file) - config = YAML.safe_load(ERB.new(File.read(config_file)).result) - assign(config) + read = File.read(config_file) + evaled = ERB.new(read).result + YAML.safe_load(evaled) end def load_env @options.values.each_with_object({}) do |option, opts| next unless (value = ENV[option.env_key])