Class: Chronos::Configuration
- Inherits:
-
Object
- Object
- Chronos::Configuration
- Defined in:
- lib/chronos/configuration.rb
Overview
Mutable configuration used only while the Chronos agent is being set up.
Constant Summary collapse
- DEFAULT_BLOCKLIST_KEYS =
%w( password password_confirmation passwd secret api_key apikey authorization token access_token refresh_token private_key client_secret cookie set-cookie session credit_card card_number cvv cpf cnpj ).freeze
- CONTEXT_STORE_METHODS =
[:get, :set, :clear, :with_context].freeze
- ATTRIBUTES =
[ :project_id, :project_key, :host, :environment, :app_version, :service_name, :root_directory, :logger, :timeout, :open_timeout, :queue_size, :workers, :enabled, :error_notifications, :ignored_environments, :proxy, :ssl_verify, :user_agent, :max_payload_size, :gzip, :blocklist_keys, :allowlist_keys, :filters, :hash_keys, :anonymize_ip, :max_retries, :retry_base_interval, :retry_max_interval, :retry_jitter, :backlog_size, :circuit_failure_threshold, :circuit_reset_timeout, :remote_configuration, :remote_config_max_bytes, :sampling_rate, :enabled_event_types, :max_remote_send_interval, :context_store, :breadcrumb_capacity, :breadcrumb_max_bytes, :rails_enabled, :rails_capture_in_console, :rails_capture_in_test, :rails_capture_user_agent, :apm_enabled, :apm_max_groups, :apm_flush_count, :apm_batch_size, :apm_max_queries_per_request, :apm_slow_query_threshold_ms, :apm_long_transaction_threshold_ms, :apm_n_plus_one_threshold, :apm_histogram_buckets ].freeze
- Snapshot =
Immutable configuration shared by all runtime components.
Class.new do attr_reader(*Configuration::ATTRIBUTES) def initialize(values) Configuration::ATTRIBUTES.each do |attribute| value = values[attribute] deep_freeze(value) instance_variable_set("@#{attribute}", value) end freeze end def enabled_for_environment? enabled && !ignored_environments.map(&:to_s).include?(environment.to_s) end private # rubocop:disable Layout/AccessModifierIndentation def deep_freeze(value) return value if value.respond_to?(:call) || context_store?(value) case value when Hash value.each do |key, child| deep_freeze(key) deep_freeze(child) end when Array value.each { |child| deep_freeze(child) } end value.freeze end def context_store?(value) Configuration::CONTEXT_STORE_METHODS.all? { |method_name| value.respond_to?(method_name) } rescue StandardError false end end
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #snapshot ⇒ Object
- #valid? ⇒ Boolean
-
#validation_errors ⇒ Object
rubocop:disable Metrics/AbcSize.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
54 55 56 57 58 59 60 |
# File 'lib/chronos/configuration.rb', line 54 def initialize initialize_core_defaults initialize_privacy_defaults initialize_resilience_defaults initialize_rails_defaults initialize_apm_defaults end |
Instance Method Details
#snapshot ⇒ Object
62 63 64 65 66 67 |
# File 'lib/chronos/configuration.rb', line 62 def snapshot errors = validation_errors raise ConfigurationError, errors.join(", ") unless errors.empty? Snapshot.new(to_hash) end |
#valid? ⇒ Boolean
69 70 71 |
# File 'lib/chronos/configuration.rb', line 69 def valid? validation_errors.empty? end |
#validation_errors ⇒ Object
rubocop:disable Metrics/AbcSize
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/chronos/configuration.rb', line 73 def validation_errors # rubocop:disable Metrics/AbcSize errors = [] if enabled errors << "project_id is required" if blank?(project_id) errors << "project_key is required" if blank?(project_key) errors.concat(host_errors) end errors << "timeout must be greater than zero" unless positive_number?(timeout) errors << "open_timeout must be greater than zero" unless positive_number?(open_timeout) errors << "queue_size must be a positive integer" unless positive_integer?(queue_size) errors << "workers must be a positive integer" unless positive_integer?(workers) errors << "max_payload_size must be a positive integer" unless positive_integer?(max_payload_size) errors.concat(resilience_errors) errors.concat(privacy_errors) errors.concat(context_errors) errors.concat(apm_errors) errors end |