Class: Hypertrace::Config::Config
- Inherits:
-
Object
- Object
- Hypertrace::Config::Config
- Includes:
- Logging
- Defined in:
- lib/hypertrace/config/config.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #load_config ⇒ Object
- #load_file ⇒ Object
- #merge_config(base_config, overriding_config) ⇒ Object
Methods included from Logging
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
5 6 7 |
# File 'lib/hypertrace/config/config.rb', line 5 def initialize @config = load_config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
4 5 6 |
# File 'lib/hypertrace/config/config.rb', line 4 def config @config end |
Instance Method Details
#load_config ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/hypertrace/config/config.rb', line 9 def load_config # Order of loading: # 1.) Defaults # 2.) Overriden by config file # 3.) Overriden by env vars config = Marshal.load(Marshal.dump(DEFAULT_AGENT_CONFIG)) file_config = load_file config = merge_config(config, file_config) env_config = Hypertrace::Config::Environment.load_config_from_env config = merge_config(config, env_config) log.info "Finalized config loaded" log.info config proto_config = Hypertrace::Agent::Config::V1::AgentConfig.new enabled = Google::Protobuf::BoolValue.new({value: config[:enabled]}) proto_config.enabled = enabled proto_config.propagation_formats += config[:propagation_formats] service_name = Google::Protobuf::StringValue.new({value: config[:service_name]}) proto_config.service_name = service_name proto_config.reporting = Hypertrace::Agent::Config::V1::Reporting.new endpoint = Google::Protobuf::StringValue.new({value: config[:reporting][:endpoint]}) proto_config.reporting.endpoint = endpoint secure = Google::Protobuf::BoolValue.new({value: config[:reporting][:secure]}) proto_config.reporting.secure = secure proto_config.reporting.trace_reporter_type = config[:reporting][:trace_reporter_type] proto_config.data_capture = Hypertrace::Agent::Config::V1::DataCapture.new %i[http_headers http_body rpc_metadata rpc_body].each do |field| = Hypertrace::Agent::Config::V1::Message.new .request = Google::Protobuf::BoolValue.new({value:config[:data_capture][field][:request]}) .response = Google::Protobuf::BoolValue.new({value:config[:data_capture][field][:response]}) proto_config.data_capture[field.to_s] = end proto_config.data_capture.body_max_size_bytes = Google::Protobuf::Int32Value.new({value: config[:data_capture][:body_max_size_bytes]}) proto_config.resource_attributes.merge(config[:resource_attributes]) proto_config end |
#load_file ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/hypertrace/config/config.rb', line 53 def load_file file_path = Hypertrace::EnvVarSettings.env_value('CONFIG_FILE') return {} if file_path.nil? begin yaml_content = File.read(file_path) config_file_contents = YAML.load(yaml_content, symbolize_names: true) rescue => e log.warn "failed to load config file: #{file_path}" end config_file_contents || {} end |
#merge_config(base_config, overriding_config) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/hypertrace/config/config.rb', line 66 def merge_config(base_config, overriding_config) overriding_config.each_key do |key| if base_config.key?(key) && base_config[key].instance_of?(Hash) base_config[key] = merge_config(base_config[key], overriding_config[key]) else base_config[key] = overriding_config[key] end end base_config end |