Module: TraceView::Config
- Defined in:
- lib/traceview/config.rb
Overview
This module exposes a nested configuration hash that can be used to configure and/or modify the functionality of the traceview gem.
Use TraceView::Config.show to view the entire nested hash.
Constant Summary collapse
- @@config =
{}
- @@instrumentation =
[:action_controller, :action_controller_api, :action_view, :active_record, :bunnyclient, :bunnyconsumer, :cassandra, :curb, :dalli, :delayed_jobclient, :delayed_jobworker, :em_http_request, :excon, :faraday, :grape, :httpclient, :nethttp, :memcached, :memcache, :mongo, :moped, :rack, :redis, :resqueclient, :resqueworker, :rest_client, :sequel, :sidekiqclient, :sidekiqworker, :typhoeus]
- @@http_clients =
Subgrouping of instrumentation
[:curb, :excon, :em_http_request, :faraday, :httpclient, :nethttp, :rest_client, :typhoeus]
Class Method Summary collapse
- .[](key) ⇒ Object
-
.[]=(key, value) ⇒ Object
[]=.
-
.initialize(_data = {}) ⇒ Object
initialize.
- .merge!(data) ⇒ Object
-
.method_missing(sym, *args) ⇒ Object
rubocop:enable Metrics/AbcSize, Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity.
-
.show ⇒ Object
Return the raw nested hash.
-
.update!(data) ⇒ Object
rubocop:enable Metrics/AbcSize.
Class Method Details
.[](key) ⇒ Object
224 225 226 227 228 229 230 231 |
# File 'lib/traceview/config.rb', line 224 def self.[](key) if key == :resque TraceView.logger.warn '[traceview/warn] :resque config is deprecated. It is now split into :resqueclient and :resqueworker.' TraceView.logger.warn "[traceview/warn] Called from #{Kernel.caller[0]}" end @@config[key.to_sym] end |
.[]=(key, value) ⇒ Object
[]=
Config variable assignment method. Here we validate and store the assigned value(s) and trigger any secondary action needed.
rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 |
# File 'lib/traceview/config.rb', line 240 def self.[]=(key, value) @@config[key.to_sym] = value if key == :sampling_rate TraceView.logger.warn 'sampling_rate is not a supported setting for TraceView::Config. ' \ 'Please use :sample_rate.' elsif key == :sample_rate unless value.is_a?(Integer) || value.is_a?(Float) fail 'traceview :sample_rate must be a number between 1 and 1000000 (1m)' end # Validate :sample_rate value unless value.between?(1, 1e6) fail 'traceview :sample_rate must be between 1 and 1000000 (1m)' end # Assure value is an integer @@config[key.to_sym] = value.to_i TraceView.set_sample_rate(value) if TraceView.loaded elsif key == :action_blacklist TraceView.logger.warn "[traceview/unsupported] :action_blacklist has been deprecated and no longer functions." elsif key == :resque TraceView.logger.warn "[traceview/warn] :resque config is deprecated. It is now split into :resqueclient and :resqueworker." TraceView.logger.warn "[traceview/warn] Called from #{Kernel.caller[0]}" elsif key == :include_url_query_params # Obey the global flag and update all of the per instrumentation # <tt>:log_args</tt> values. @@config[:rack][:log_args] = value elsif key == :include_remote_url_params # Obey the global flag and update all of the per instrumentation # <tt>:log_args</tt> values. @@http_clients.each do |i| @@config[i][:log_args] = value end end # Update liboboe if updating :tracing_mode if key == :tracing_mode TraceView.set_tracing_mode(value.to_sym) if TraceView.loaded # Make sure that the mode is stored as a symbol @@config[key.to_sym] = value.to_sym end end |
.initialize(_data = {}) ⇒ Object
initialize
Initializer method to set everything up with a default configuration.
rubocop:disable Metrics/AbcSize
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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 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 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/traceview/config.rb', line 40 def self.initialize(_data = {}) # Setup default instrumentation values @@instrumentation.each do |k| @@config[k] = {} @@config[k][:enabled] = true @@config[k][:collect_backtraces] = false @@config[k][:log_args] = true end # Beta instrumentation disabled by default TraceView::Config[:em_http_request][:enabled] = false # Set collect_backtraces defaults TraceView::Config[:action_controller][:collect_backtraces] = false TraceView::Config[:action_controller_api][:collect_backtraces] = false TraceView::Config[:active_record][:collect_backtraces] = true TraceView::Config[:bunnyclient][:collect_backtraces] = false TraceView::Config[:bunnyconsumer][:collect_backtraces] = false TraceView::Config[:action_view][:collect_backtraces] = true TraceView::Config[:cassandra][:collect_backtraces] = true TraceView::Config[:curb][:collect_backtraces] = true TraceView::Config[:dalli][:collect_backtraces] = false TraceView::Config[:delayed_jobclient][:collect_backtraces] = false TraceView::Config[:delayed_jobworker][:collect_backtraces] = false TraceView::Config[:em_http_request][:collect_backtraces] = false TraceView::Config[:excon][:collect_backtraces] = true TraceView::Config[:faraday][:collect_backtraces] = false TraceView::Config[:grape][:collect_backtraces] = true TraceView::Config[:httpclient][:collect_backtraces] = true TraceView::Config[:memcache][:collect_backtraces] = false TraceView::Config[:memcached][:collect_backtraces] = false TraceView::Config[:mongo][:collect_backtraces] = true TraceView::Config[:moped][:collect_backtraces] = true TraceView::Config[:nethttp][:collect_backtraces] = true TraceView::Config[:rack][:collect_backtraces] = false TraceView::Config[:redis][:collect_backtraces] = false TraceView::Config[:resqueclient][:collect_backtraces] = true TraceView::Config[:resqueworker][:collect_backtraces] = false TraceView::Config[:rest_client][:collect_backtraces] = false TraceView::Config[:sequel][:collect_backtraces] = true TraceView::Config[:sidekiqclient][:collect_backtraces] = false TraceView::Config[:sidekiqworker][:collect_backtraces] = false TraceView::Config[:typhoeus][:collect_backtraces] = false # Legacy Resque config support. To be removed in a future version @@config[:resque] = {} # Setup an empty host blacklist (see: TraceView::API::Util.blacklisted?) @@config[:blacklist] = [] # Access Key is empty until loaded from config file or env var @@config[:access_key] = '' # Logging of outgoing HTTP query args # # This optionally disables the logging of query args of outgoing # HTTP clients such as Net::HTTP, excon, typhoeus and others. # # This flag is global to all HTTP client instrumentation. # # To configure this on a per instrumentation basis, set this # option to true and instead disable the instrumenstation specific # option <tt>log_args</tt>: # # TraceView::Config[:nethttp][:log_args] = false # TraceView::Config[:excon][:log_args] = false # TraceView::Config[:typhoeus][:log_args] = true # @@config[:include_url_query_params] = true # Logging of incoming HTTP query args # # This optionally disables the logging of incoming URL request # query args. # # This flag is global and currently only affects the Rack # instrumentation which reports incoming request URLs and # query args by default. @@config[:include_remote_url_params] = true # The TraceView Ruby gem has the ability to sanitize query literals # from SQL statements. By default this is disabled. Enable to # avoid collecting and reporting query literals to TraceView. @@config[:sanitize_sql] = false # The regular expression used to sanitize SQL. @@config[:sanitize_sql_regexp] = '(\'[\s\S][^\']*\'|\d*\.\d+|\d+|NULL)' @@config[:sanitize_sql_opts] = Regexp::IGNORECASE # Do Not Trace # These two values allow you to configure specific URL patterns to # never be traced. By default, this is set to common static file # extensions but you may want to customize this list for your needs. # # dnt_regexp and dnt_opts is passed to Regexp.new to create # a regular expression object. That is then used to match against # the incoming request path. # # The path string originates from the rack layer and is retrieved # as follows: # # req = ::Rack::Request.new(env) # path = URI.unescape(req.path) # # Usage: # TraceView::Config[:dnt_regexp] = "lobster$" # TraceView::Config[:dnt_opts] = Regexp::IGNORECASE # # This will ignore all requests that end with the string lobster # regardless of case # # Requests with positive matches (non nil) will not be traced. # See lib/traceview/util.rb: TraceView::Util.static_asset? # @@config[:dnt_regexp] = '\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|ttf|woff|svg|less)$' @@config[:dnt_opts] = Regexp::IGNORECASE # In Rails, raised exceptions with rescue handlers via # <tt>rescue_from</tt> are not reported to the TraceView # dashboard by default. Setting this value to true will # report all raised exception regardless. # @@config[:report_rescued_errors] = false # By default, the curb instrumentation will not link # outgoing requests with remotely instrumented # webservers (aka cross host tracing). This is because the # instrumentation can't detect if the independent libcurl # instrumentation is in use or not. # # If you're sure that it's not in use/installed, then you can # enable cross host tracing for the curb HTTP client # here. Set TraceView::Config[:curb][:cross_host] to true # to enable. # # Alternatively, if you would like to install the separate # libcurl instrumentation, see here: # http://docs.traceview.solarwinds.com/Instrumentation/other-instrumentation-modules.html#libcurl # @@config[:curb][:cross_host] = false # The bunny (Rabbitmq) instrumentation can optionally report # Controller and Action values to allow filtering of bunny # message handling in # the UI. Use of Controller and Action # for filters is temporary until the UI is updated with # additional filters. # # These values identify which properties of # Bunny::MessageProperties to report as Controller # and Action. The defaults are to report :app_id (as # Controller) and :type (as Action). If these values # are not specified in the publish, then nothing # will be reported here. # @@config[:bunnyconsumer][:controller] = :app_id @@config[:bunnyconsumer][:action] = :type # Environment support for OpenShift. if ENV.key?('OPENSHIFT_TRACEVIEW_TLYZER_IP') # We're running on OpenShift @@config[:tracing_mode] = :always @@config[:reporter_host] = ENV['OPENSHIFT_TRACEVIEW_TLYZER_IP'] @@config[:reporter_port] = ENV['OPENSHIFT_TRACEVIEW_TLYZER_PORT'] else # The default configuration @@config[:tracing_mode] = :through @@config[:reporter_host] = '127.0.0.1' @@config[:reporter_port] = '7831' end @@config[:verbose] = ENV.key?('TRACEVIEW_GEM_VERBOSE') ? true : false end |
.merge!(data) ⇒ Object
220 221 222 |
# File 'lib/traceview/config.rb', line 220 def self.merge!(data) update!(data) end |
.method_missing(sym, *args) ⇒ Object
rubocop:enable Metrics/AbcSize, Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 |
# File 'lib/traceview/config.rb', line 291 def self.method_missing(sym, *args) class_var_name = "@@#{sym}" if sym.to_s =~ /(.+)=$/ self[$1] = args.first else # Try part of the @@config hash first if @@config.key?(sym) self[sym] # Then try as a class variable elsif self.class_variable_defined?(class_var_name.to_sym) self.class_eval(class_var_name) # Congrats - You've won a brand new nil... else nil end end end |
.show ⇒ Object
Return the raw nested hash.
29 30 31 |
# File 'lib/traceview/config.rb', line 29 def self.show @@config end |
.update!(data) ⇒ Object
rubocop:enable Metrics/AbcSize
214 215 216 217 218 |
# File 'lib/traceview/config.rb', line 214 def self.update!(data) data.each do |key, value| self[key] = value end end |