lib/contrast/components/config.rb in contrast-agent-6.8.0 vs lib/contrast/components/config.rb in contrast-agent-6.9.0
- old
+ new
@@ -2,10 +2,11 @@
# frozen_string_literal: true
require 'contrast/utils/env_configuration_item'
require 'ougai'
require 'contrast/configuration'
+require 'contrast/config/diagnostics'
module Contrast
module Components
# This component encapsulates reference to the configuration file.
# At the time of writing, the configuration file is a yaml file reflecting
@@ -24,10 +25,11 @@
# time than to silently fail to deliver functionality.
module Config
CONTRAST_ENV_MARKER = 'CONTRAST__'
CONTRAST_LOG = 'contrast_agent.log'
CONTRAST_NAME = 'Contrast Agent'
+ DATE_TIME = '%Y-%m-%dT%H:%M:%S.%L%z'
class Interface # :nodoc: # rubocop:disable Metrics/ClassLength
SESSION_VARIABLES = 'Invalid configuration. '\
"Setting both application.session_id and application.session_metadata is not allowed.\n"
API_URL = "Invalid configuration. Missing a required connection value 'url' is not set."
@@ -48,11 +50,11 @@
@_proto_logger ||= begin
@_proto_logger = ::Ougai::Logger.new(logger_path || CONTRAST_LOG)
@_proto_logger.progname = CONTRAST_NAME
@_proto_logger.level = ::Ougai::Logging::Severity::WARN
@_proto_logger.formatter = Contrast::Logger::Format.new
- @_proto_logger.formatter.datetime_format = '%Y-%m-%dT%H:%M:%S.%L%z'
+ @_proto_logger.formatter.datetime_format = DATE_TIME
@_proto_logger
end
end
def build
@@ -107,10 +109,14 @@
def enable
@config.enable
end
+ def sources
+ @config.sources
+ end
+
def invalid?
!valid?
end
def loggable
@@ -128,10 +134,15 @@
# @return [String,nil] the value of the session metadata set in the configuration, or nil if unset
def session_metadata
application.session_metadata
end
+ # @return [String, nil] the path to the YAML config file, if any.
+ def config_file_path
+ config.config_file
+ end
+
private
# The config has information about how to construct the logger. If the config is invalid, and you want to know
# about it, then you have a circular dependency if you try to log it, so we use basic proto_logger to do this
# job.
@@ -219,10 +230,15 @@
# @return [String, nil]
def logger_path
agent.logger.path
end
+ # This methods is here to add the proper forward towards @config
+ def enable= value
+ @config.enable = value
+ end
+
# Assign the value from an ENV variable to the Contrast::Config::RootConfiguration object, when
# appropriate.
#
# @return nil
def assign_value_to_path_array current_level, dot_path_array, value
@@ -231,9 +247,10 @@
current_level = current_level.send(segment) if current_level.cs__respond_to?(segment)
end
return unless current_level.nil? == false && current_level.cs__respond_to?(dot_path_array[-1])
current_level.send("#{ dot_path_array[-1] }=", value)
+ sources.set(dot_path_array.join('.'), Contrast::Components::Config::Sources::ENVIRONMENT)
end
end
end
end
end