Class: Instana::Config
- Inherits:
-
Object
- Object
- Instana::Config
- Defined in:
- lib/instana/config.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
-
#apply_default_stack_trace_config ⇒ Object
Apply default stack trace configuration.
-
#get_stack_trace_config(technology) ⇒ Hash
Get stack trace configuration for a specific technology Falls back to global configuration if technology-specific config is not found.
-
#initialize(logger: ::Instana.logger, agent_host: ENV['INSTANA_AGENT_HOST'], agent_port: ENV['INSTANA_AGENT_PORT']) ⇒ Config
constructor
A new instance of Config.
-
#read_config_from_agent(discovery) ⇒ Object
Read configuration from agent discovery response This is called after agent discovery is complete.
-
#read_span_stack_config ⇒ Object
Read stack trace configuration from environment variables, YAML file, or use defaults Priority: Environment variables > YAML file > Agent discovery > Defaults.
-
#read_span_stack_config_from_agent(tracing_config) ⇒ Object
Read stack trace configuration from agent discovery.
-
#read_span_stack_config_from_env ⇒ Object
Read stack trace configuration from environment variables.
-
#read_span_stack_config_from_yaml ⇒ Object
Read stack trace configuration from YAML file Returns hash with :global and :technologies keys or nil if not found.
-
#should_read_from_agent?(config_key) ⇒ Boolean
Check if we should read configuration from agent Returns true if config was not set from YAML or environment variables.
Constructor Details
#initialize(logger: ::Instana.logger, agent_host: ENV['INSTANA_AGENT_HOST'], agent_port: ENV['INSTANA_AGENT_PORT']) ⇒ Config
Returns a new instance of Config.
8 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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/instana/config.rb', line 8 def initialize(logger: ::Instana.logger, agent_host: ENV['INSTANA_AGENT_HOST'], agent_port: ENV['INSTANA_AGENT_PORT']) @config = {} if agent_host logger.debug "Using custom agent host location specified in INSTANA_AGENT_HOST (#{ENV['INSTANA_AGENT_HOST']})" @config[:agent_host] = agent_host else @config[:agent_host] = '127.0.0.1' end if agent_port logger.debug "Using custom agent port specified in INSTANA_AGENT_PORT (#{ENV['INSTANA_AGENT_PORT']})" @config[:agent_port] = agent_port else @config[:agent_port] = 42699 end # Enable/disable metrics globally or individually (default: all enabled) @config[:metrics] = { :enabled => true } @config[:metrics][:gc] = { :enabled => true } @config[:metrics][:memory] = { :enabled => true } @config[:metrics][:thread] = { :enabled => true } # Enable/disable tracing (default: enabled) @config[:tracing] = { :enabled => true } # Enable/disable tracing exit spans as root spans @config[:allow_exit_as_root] = ENV['INSTANA_ALLOW_EXIT_AS_ROOT'] == '1' # Enable/Disable logging @config[:logging] = { :enabled => true } # Collector interval @config[:collector] = { :enabled => true, :interval => 1 } # EUM Related @config[:eum_api_key] = nil @config[:eum_baggage] = {} # In Ruby, backtrace collection is very expensive so it's # (unfortunately) disabled by default. If you still want # backtraces, it can be enabled with this config option. # @config[:back_trace][:stack_trace_level] = all # @config[:back_trace] = { stack_trace_level: nil } read_span_stack_config # By default, collected SQL will be sanitized to remove potentially sensitive bind params such as: # > SELECT "blocks".* FROM "blocks" WHERE "blocks"."name" = "Mr. Smith" # # ...would be sanitized to be: # > SELECT "blocks".* FROM "blocks" WHERE "blocks"."name" = ? # # This sanitization step can be disabled by setting the following value to false. # ::Instana.config[:sanitize_sql] = false @config[:sanitize_sql] = true # W3C Trace Context Support @config[:w3c_trace_correlation] = ENV['INSTANA_DISABLE_W3C_TRACE_CORRELATION'].nil? @config[:post_fork_proc] = proc { ::Instana.agent.spawn_background_thread } @config[:action_controller] = { :enabled => true } @config[:action_view] = { :enabled => true } @config[:active_record] = { :enabled => true } @config[:bunny] = { :enabled => true } @config[:dalli] = { :enabled => true } @config[:excon] = { :enabled => true } @config[:grpc] = { :enabled => true } @config[:graphql] = { :enabled => true } @config[:nethttp] = { :enabled => true } @config[:redis] = { :enabled => true } @config[:'resque-client'] = { :enabled => true, :propagate => true } @config[:'resque-worker'] = { :enabled => true, :'setup-fork' => true } @config[:'rest-client'] = { :enabled => true } @config[:sequel] = { :enabled => true } @config[:'sidekiq-client'] = { :enabled => true } @config[:'sidekiq-worker'] = { :enabled => true } end |
Instance Method Details
#[](key) ⇒ Object
85 86 87 |
# File 'lib/instana/config.rb', line 85 def [](key) @config[key.to_sym] end |
#[]=(key, value) ⇒ Object
89 90 91 |
# File 'lib/instana/config.rb', line 89 def []=(key, value) @config[key.to_sym] = value end |
#apply_default_stack_trace_config ⇒ Object
Apply default stack trace configuration
188 189 190 191 192 193 194 195 |
# File 'lib/instana/config.rb', line 188 def apply_default_stack_trace_config @config[:back_trace] = { stack_trace_level: 'error', stack_trace_length: 30, config_source: 'default' } @config[:back_trace_technologies] = {} end |
#get_stack_trace_config(technology) ⇒ Hash
Get stack trace configuration for a specific technology Falls back to global configuration if technology-specific config is not found
210 211 212 213 214 215 216 217 218 |
# File 'lib/instana/config.rb', line 210 def get_stack_trace_config(technology) tech_config = @config[:back_trace_technologies]&.[](technology) global_config = @config[:back_trace] || {} { stack_trace_level: tech_config&.[](:stack_trace_level) || global_config[:stack_trace_level] || 'error', stack_trace_length: tech_config&.[](:stack_trace_length) || global_config[:stack_trace_length] || 30 } end |
#read_config_from_agent(discovery) ⇒ Object
Read configuration from agent discovery response This is called after agent discovery is complete
118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/instana/config.rb', line 118 def read_config_from_agent(discovery) return unless discovery.is_a?(Hash) && discovery['tracing'] tracing_config = discovery['tracing'] # Read stack trace configuration from agent if not already set from YAML or env read_span_stack_config_from_agent(tracing_config) if should_read_from_agent?(:back_trace) # Read span filtering configuration from agent ::Instana.span_filtering_config&.read_config_from_agent(discovery) rescue => e ::Instana.logger.warn("Failed to read configuration from agent: #{e.}") end |
#read_span_stack_config ⇒ Object
Read stack trace configuration from environment variables, YAML file, or use defaults Priority: Environment variables > YAML file > Agent discovery > Defaults
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/instana/config.rb', line 95 def read_span_stack_config # Try environment variables first if ENV['INSTANA_STACK_TRACE'] || ENV['INSTANA_STACK_TRACE_LENGTH'] read_span_stack_config_from_env @config[:back_trace_technologies] = {} return end # Try YAML file yaml_config = read_span_stack_config_from_yaml if yaml_config @config[:back_trace] = yaml_config[:global] @config[:back_trace_technologies] = yaml_config[:technologies] || {} return end # Use defaults apply_default_stack_trace_config end |
#read_span_stack_config_from_agent(tracing_config) ⇒ Object
Read stack trace configuration from agent discovery
133 134 135 136 137 138 139 140 141 |
# File 'lib/instana/config.rb', line 133 def read_span_stack_config_from_agent(tracing_config) return unless tracing_config['global'] global_config = parse_global_stack_trace_config(tracing_config['global'], 'agent') @config[:back_trace] = global_config if global_config # Read technology-specific configurations @config[:back_trace_technologies] = parse_technology_configs(tracing_config) end |
#read_span_stack_config_from_env ⇒ Object
Read stack trace configuration from environment variables
179 180 181 182 183 184 185 |
# File 'lib/instana/config.rb', line 179 def read_span_stack_config_from_env @config[:back_trace] = { stack_trace_level: ENV['INSTANA_STACK_TRACE'] || 'error', stack_trace_length: ENV['INSTANA_STACK_TRACE_LENGTH']&.to_i || 30, config_source: 'env' } end |
#read_span_stack_config_from_yaml ⇒ Object
Read stack trace configuration from YAML file Returns hash with :global and :technologies keys or nil if not found
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/instana/config.rb', line 145 def read_span_stack_config_from_yaml config_path = ENV['INSTANA_CONFIG_PATH'] return nil unless config_path && File.exist?(config_path) begin yaml_content = YAML.safe_load(File.read(config_path)) # Support both "tracing" and "com.instana.tracing" as top-level keys if yaml_content['com.instana.tracing'] ::Instana.logger.warn('Please use "tracing" instead of "com.instana.tracing"') end tracing_config = yaml_content['tracing'] || yaml_content['com.instana.tracing'] return nil unless tracing_config result = {} # Look for global stack trace configuration if tracing_config['global'] global_config = parse_global_stack_trace_config(tracing_config['global'], 'yaml') result[:global] = global_config if global_config end # Look for technology-specific configurations technologies = parse_technology_configs(tracing_config) result[:technologies] = technologies unless technologies.empty? result.empty? ? nil : result rescue => e ::Instana.logger.warn("Failed to load stack trace configuration from YAML: #{e.}") nil end end |
#should_read_from_agent?(config_key) ⇒ Boolean
Check if we should read configuration from agent Returns true if config was not set from YAML or environment variables
199 200 201 202 203 204 |
# File 'lib/instana/config.rb', line 199 def should_read_from_agent?(config_key) return true unless @config[config_key] source = @config[config_key][:config_source] source.nil? || source == 'default' end |