lib/elastic_apm/config.rb in elastic-apm-3.12.1 vs lib/elastic_apm/config.rb in elastic-apm-3.13.0

- old
+ new

@@ -17,10 +17,11 @@ # frozen_string_literal: true require 'elastic_apm/config/bytes' require 'elastic_apm/config/duration' +require 'elastic_apm/config/log_level_map' require 'elastic_apm/config/options' require 'elastic_apm/config/round_float' require 'elastic_apm/config/regexp_list' require 'elastic_apm/config/wildcard_pattern_list' @@ -30,15 +31,17 @@ extend Options DEPRECATED_OPTIONS = %i[].freeze # DEPRECATED: To align with other agents, change on next major bump to: - # "password, passwd, pwd, secret, *key, *token*, *session*, *credit*, *card*, authorization, set-cookie" + # "password, passwd, pwd, secret, *key, *token*, *session*, *credit*, + # *card*, authorization, set-cookie" SANITIZE_FIELD_NAMES_DEFAULT = - %w[*password* *passwd* *pwd* *secret* *key* *token* *session* *credit* *card* *authorization* *set-cookie*] + %w[*password* *passwd* *pwd* *secret* *key* *token* *session* + *credit* *card* *authorization* *set-cookie*].freeze - # rubocop:disable Metrics/LineLength, Layout/ExtraSpacing + # rubocop:disable Layout/LineLength, Layout/ExtraSpacing option :config_file, type: :string, default: 'config/elastic_apm.yml' option :server_url, type: :url, default: 'http://localhost:8200' option :secret_token, type: :string option :api_key, type: :string @@ -71,23 +74,22 @@ option :hostname, type: :string option :http_compression, type: :bool, default: true option :ignore_url_patterns, type: :list, default: [], converter: RegexpList.new option :instrument, type: :bool, default: true option :instrumented_rake_tasks, type: :list, default: [] - option :log_level, type: :int, default: Logger::INFO + option :log_level, type: :int, default: Logger::INFO, converter: LogLevelMap.new option :log_path, type: :string option :metrics_interval, type: :int, default: '30s', converter: Duration.new option :pool_size, type: :int, default: 1 option :proxy_address, type: :string option :proxy_headers, type: :dict option :proxy_password, type: :string option :proxy_port, type: :int option :proxy_username, type: :string option :recording, type: :bool, default: true - option :sanitize_field_names, type: :list, - default: SANITIZE_FIELD_NAMES_DEFAULT, converter: WildcardPatternList.new - option :server_ca_cert, type: :string + option :sanitize_field_names, type: :list, default: SANITIZE_FIELD_NAMES_DEFAULT, converter: WildcardPatternList.new + option :server_ca_cert_file, type: :string option :service_name, type: :string option :service_node_name, type: :string option :service_version, type: :string option :source_lines_error_app_frames, type: :int, default: 5 option :source_lines_error_library_frames, type: :int, default: 0 @@ -100,11 +102,11 @@ option :transaction_sample_rate, type: :float, default: 1.0, converter: RoundFloat.new option :use_elastic_traceparent_header, type: :bool, default: true option :use_legacy_sql_parser, type: :bool, default: false option :verify_server_cert, type: :bool, default: true - # rubocop:enable Metrics/LineLength, Layout/ExtraSpacing + # rubocop:enable Layout/LineLength, Layout/ExtraSpacing def initialize(options = {}) @options = load_schema assign(options) @@ -124,12 +126,11 @@ @__view_paths ||= [] @__root_path ||= Dir.pwd end - attr_accessor :__view_paths, :__root_path - attr_accessor :logger + attr_accessor :__view_paths, :__root_path, :logger attr_reader :options def assign(update) return unless update @@ -199,12 +200,13 @@ # DEPRECATED: Remove this in next major version def sanitize_field_names=(value) list = WildcardPatternList.new.call(value) defaults = WildcardPatternList.new.call(SANITIZE_FIELD_NAMES_DEFAULT) + # use regex pattern for comparisons get(:sanitize_field_names).value = - defaults.concat(list).uniq(&:pattern) # use regex pattern for comparisons + defaults.concat(list).uniq(&:pattern) end def span_frames_min_duration? span_frames_min_duration != 0 end @@ -221,12 +223,12 @@ def ssl_context return unless use_ssl? @ssl_context ||= OpenSSL::SSL::SSLContext.new.tap do |context| - if server_ca_cert - context.ca_file = server_ca_cert + if server_ca_cert_file + context.ca_file = server_ca_cert_file else context.cert_store = OpenSSL::X509::Store.new.tap(&:set_default_paths) end @@ -276,27 +278,38 @@ def active enabled end alias active? active + def server_ca_cert + server_ca_cert_file + end + def disabled_instrumentations=(value) warn '[DEPRECATED] The option disabled_instrumentations has been ' \ 'renamed to disable_instrumentations to align with other agents.' self.disable_instrumentations = value end - def use_experimental_sql_parser=(value) - warn '[DEPRECATED] The new SQL parser is now the default. To use the old one, ' - 'use use_legacy_sql_parser and please report why you wish to do so.' + def use_experimental_sql_parser=(_value) + warn '[DEPRECATED] The new SQL parser is now the default. To use the ' \ + 'old one, use use_legacy_sql_parser and please report why you ' \ + 'wish to do so.' end def active=(value) warn '[DEPRECATED] The option active has been renamed to enabled ' \ 'to align with other agents and with the remote config.' self.enabled = value end + def server_ca_cert=(value) + warn '[DEPRECATED] The option server_ca_cert has been ' \ + 'renamed to server_ca_cert_file to align with other agents.' + self.server_ca_cert_file = value + end + private def load_config_file return unless File.exist?(config_file) @@ -311,11 +324,11 @@ opts[option.key] = value end end def build_logger - Logger.new(log_path == '-' ? STDOUT : log_path).tap do |logger| + Logger.new(log_path == '-' ? $stdout : log_path).tap do |logger| logger.level = log_level end end def app_type?(app) @@ -342,10 +355,11 @@ self.framework_name ||= 'Ruby on Rails' self.framework_version ||= ::Rails::VERSION::STRING self.logger ||= ::Rails.logger self.__root_path = ::Rails.root.to_s - self.__view_paths = app.config.paths['app/views'].existent + [::Rails.root.to_s] + self.__view_paths = app.config.paths['app/views'].existent + + [::Rails.root.to_s] end def rails_app_name(app) if ::Rails::VERSION::MAJOR >= 6 app.class.module_parent_name