Class: OpenTrace::Config
- Inherits:
-
Object
- Object
- OpenTrace::Config
- Defined in:
- lib/opentrace/config.rb
Constant Summary collapse
- REQUIRED_FIELDS =
%i[endpoint api_key service].freeze
- LEVELS =
{ debug: 0, info: 1, warn: 2, error: 3, fatal: 4 }.freeze
- LEVEL_TO_LOGGER_SEVERITY =
Maps OpenTrace min_level to Ruby Logger severity constant. Used by LogForwarder to set its level so BroadcastLogger doesn’t downgrade the effective log level for the entire app.
{ debug: 0, # ::Logger::DEBUG info: 1, # ::Logger::INFO warn: 2, # ::Logger::WARN error: 3, # ::Logger::ERROR fatal: 4 # ::Logger::FATAL }.freeze
Instance Attribute Summary collapse
-
#allowed_levels ⇒ Object
Returns the value of attribute allowed_levels.
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#batch_size ⇒ Object
Returns the value of attribute batch_size.
-
#circuit_breaker_threshold ⇒ Object
Returns the value of attribute circuit_breaker_threshold.
-
#circuit_breaker_timeout ⇒ Object
Returns the value of attribute circuit_breaker_timeout.
-
#compression ⇒ Object
Returns the value of attribute compression.
-
#compression_threshold ⇒ Object
Returns the value of attribute compression_threshold.
-
#context ⇒ Object
Returns the value of attribute context.
-
#enabled ⇒ Object
Returns the value of attribute enabled.
-
#endpoint ⇒ Object
Returns the value of attribute endpoint.
-
#environment ⇒ Object
Returns the value of attribute environment.
-
#flush_interval ⇒ Object
Returns the value of attribute flush_interval.
-
#git_sha ⇒ Object
Returns the value of attribute git_sha.
-
#hostname ⇒ Object
Returns the value of attribute hostname.
-
#http_tracking ⇒ Object
Returns the value of attribute http_tracking.
-
#ignore_paths ⇒ Object
Returns the value of attribute ignore_paths.
-
#max_payload_bytes ⇒ Object
Returns the value of attribute max_payload_bytes.
-
#max_retries ⇒ Object
Returns the value of attribute max_retries.
-
#memory_tracking ⇒ Object
Returns the value of attribute memory_tracking.
-
#min_level ⇒ Object
Returns the value of attribute min_level.
-
#on_drop ⇒ Object
Returns the value of attribute on_drop.
-
#pid ⇒ Object
Returns the value of attribute pid.
-
#pool_monitoring ⇒ Object
Returns the value of attribute pool_monitoring.
-
#pool_monitoring_interval ⇒ Object
Returns the value of attribute pool_monitoring_interval.
-
#queue_monitoring ⇒ Object
Returns the value of attribute queue_monitoring.
-
#queue_monitoring_interval ⇒ Object
Returns the value of attribute queue_monitoring_interval.
-
#rate_limit_backoff ⇒ Object
Returns the value of attribute rate_limit_backoff.
-
#request_summary ⇒ Object
Returns the value of attribute request_summary.
-
#retry_base_delay ⇒ Object
Returns the value of attribute retry_base_delay.
-
#retry_max_delay ⇒ Object
Returns the value of attribute retry_max_delay.
-
#service ⇒ Object
Returns the value of attribute service.
-
#sql_duration_threshold_ms ⇒ Object
Returns the value of attribute sql_duration_threshold_ms.
-
#sql_logging ⇒ Object
Returns the value of attribute sql_logging.
-
#timeline ⇒ Object
Returns the value of attribute timeline.
-
#timeline_max_events ⇒ Object
Returns the value of attribute timeline_max_events.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
-
#trace_propagation ⇒ Object
Returns the value of attribute trace_propagation.
Instance Method Summary collapse
- #enabled? ⇒ Boolean
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #level_allowed?(level) ⇒ Boolean
- #logger_severity ⇒ Object
- #min_level_value ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
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 |
# File 'lib/opentrace/config.rb', line 25 def initialize @endpoint = nil @api_key = nil @service = nil @environment = nil @timeout = 1.0 @enabled = true @context = nil # nil | Hash | Proc @min_level = :debug # send everything by default @allowed_levels = nil # nil = use min_level threshold (backward compatible) @hostname = nil @pid = nil @git_sha = nil @batch_size = 50 @flush_interval = 5.0 @max_retries = 2 @retry_base_delay = 0.1 @retry_max_delay = 2.0 @circuit_breaker_threshold = 5 @circuit_breaker_timeout = 30 @rate_limit_backoff = 5.0 @on_drop = nil # ->(count, reason) { ... } @compression = true @compression_threshold = 1024 # only compress payloads > 1KB @sql_logging = true @sql_duration_threshold_ms = 0.0 @ignore_paths = [] @pool_monitoring = false @pool_monitoring_interval = 30 @queue_monitoring = false @queue_monitoring_interval = 60 @request_summary = true @timeline = true @timeline_max_events = 200 @memory_tracking = false @http_tracking = false @max_payload_bytes = 262_144 # 256 KB @trace_propagation = true end |
Instance Attribute Details
#allowed_levels ⇒ Object
Returns the value of attribute allowed_levels.
8 9 10 |
# File 'lib/opentrace/config.rb', line 8 def allowed_levels @allowed_levels end |
#api_key ⇒ Object
Returns the value of attribute api_key.
8 9 10 |
# File 'lib/opentrace/config.rb', line 8 def api_key @api_key end |
#batch_size ⇒ Object
Returns the value of attribute batch_size.
8 9 10 |
# File 'lib/opentrace/config.rb', line 8 def batch_size @batch_size end |
#circuit_breaker_threshold ⇒ Object
Returns the value of attribute circuit_breaker_threshold.
8 9 10 |
# File 'lib/opentrace/config.rb', line 8 def circuit_breaker_threshold @circuit_breaker_threshold end |
#circuit_breaker_timeout ⇒ Object
Returns the value of attribute circuit_breaker_timeout.
8 9 10 |
# File 'lib/opentrace/config.rb', line 8 def circuit_breaker_timeout @circuit_breaker_timeout end |
#compression ⇒ Object
Returns the value of attribute compression.
8 9 10 |
# File 'lib/opentrace/config.rb', line 8 def compression @compression end |
#compression_threshold ⇒ Object
Returns the value of attribute compression_threshold.
8 9 10 |
# File 'lib/opentrace/config.rb', line 8 def compression_threshold @compression_threshold end |
#context ⇒ Object
Returns the value of attribute context.
8 9 10 |
# File 'lib/opentrace/config.rb', line 8 def context @context end |
#enabled ⇒ Object
Returns the value of attribute enabled.
8 9 10 |
# File 'lib/opentrace/config.rb', line 8 def enabled @enabled end |
#endpoint ⇒ Object
Returns the value of attribute endpoint.
8 9 10 |
# File 'lib/opentrace/config.rb', line 8 def endpoint @endpoint end |
#environment ⇒ Object
Returns the value of attribute environment.
8 9 10 |
# File 'lib/opentrace/config.rb', line 8 def environment @environment end |
#flush_interval ⇒ Object
Returns the value of attribute flush_interval.
8 9 10 |
# File 'lib/opentrace/config.rb', line 8 def flush_interval @flush_interval end |
#git_sha ⇒ Object
Returns the value of attribute git_sha.
8 9 10 |
# File 'lib/opentrace/config.rb', line 8 def git_sha @git_sha end |
#hostname ⇒ Object
Returns the value of attribute hostname.
8 9 10 |
# File 'lib/opentrace/config.rb', line 8 def hostname @hostname end |
#http_tracking ⇒ Object
Returns the value of attribute http_tracking.
8 9 10 |
# File 'lib/opentrace/config.rb', line 8 def http_tracking @http_tracking end |
#ignore_paths ⇒ Object
Returns the value of attribute ignore_paths.
8 9 10 |
# File 'lib/opentrace/config.rb', line 8 def ignore_paths @ignore_paths end |
#max_payload_bytes ⇒ Object
Returns the value of attribute max_payload_bytes.
8 9 10 |
# File 'lib/opentrace/config.rb', line 8 def max_payload_bytes @max_payload_bytes end |
#max_retries ⇒ Object
Returns the value of attribute max_retries.
8 9 10 |
# File 'lib/opentrace/config.rb', line 8 def max_retries @max_retries end |
#memory_tracking ⇒ Object
Returns the value of attribute memory_tracking.
8 9 10 |
# File 'lib/opentrace/config.rb', line 8 def memory_tracking @memory_tracking end |
#min_level ⇒ Object
Returns the value of attribute min_level.
8 9 10 |
# File 'lib/opentrace/config.rb', line 8 def min_level @min_level end |
#on_drop ⇒ Object
Returns the value of attribute on_drop.
8 9 10 |
# File 'lib/opentrace/config.rb', line 8 def on_drop @on_drop end |
#pid ⇒ Object
Returns the value of attribute pid.
8 9 10 |
# File 'lib/opentrace/config.rb', line 8 def pid @pid end |
#pool_monitoring ⇒ Object
Returns the value of attribute pool_monitoring.
8 9 10 |
# File 'lib/opentrace/config.rb', line 8 def pool_monitoring @pool_monitoring end |
#pool_monitoring_interval ⇒ Object
Returns the value of attribute pool_monitoring_interval.
8 9 10 |
# File 'lib/opentrace/config.rb', line 8 def pool_monitoring_interval @pool_monitoring_interval end |
#queue_monitoring ⇒ Object
Returns the value of attribute queue_monitoring.
8 9 10 |
# File 'lib/opentrace/config.rb', line 8 def queue_monitoring @queue_monitoring end |
#queue_monitoring_interval ⇒ Object
Returns the value of attribute queue_monitoring_interval.
8 9 10 |
# File 'lib/opentrace/config.rb', line 8 def queue_monitoring_interval @queue_monitoring_interval end |
#rate_limit_backoff ⇒ Object
Returns the value of attribute rate_limit_backoff.
8 9 10 |
# File 'lib/opentrace/config.rb', line 8 def rate_limit_backoff @rate_limit_backoff end |
#request_summary ⇒ Object
Returns the value of attribute request_summary.
8 9 10 |
# File 'lib/opentrace/config.rb', line 8 def request_summary @request_summary end |
#retry_base_delay ⇒ Object
Returns the value of attribute retry_base_delay.
8 9 10 |
# File 'lib/opentrace/config.rb', line 8 def retry_base_delay @retry_base_delay end |
#retry_max_delay ⇒ Object
Returns the value of attribute retry_max_delay.
8 9 10 |
# File 'lib/opentrace/config.rb', line 8 def retry_max_delay @retry_max_delay end |
#service ⇒ Object
Returns the value of attribute service.
8 9 10 |
# File 'lib/opentrace/config.rb', line 8 def service @service end |
#sql_duration_threshold_ms ⇒ Object
Returns the value of attribute sql_duration_threshold_ms.
8 9 10 |
# File 'lib/opentrace/config.rb', line 8 def sql_duration_threshold_ms @sql_duration_threshold_ms end |
#sql_logging ⇒ Object
Returns the value of attribute sql_logging.
8 9 10 |
# File 'lib/opentrace/config.rb', line 8 def sql_logging @sql_logging end |
#timeline ⇒ Object
Returns the value of attribute timeline.
8 9 10 |
# File 'lib/opentrace/config.rb', line 8 def timeline @timeline end |
#timeline_max_events ⇒ Object
Returns the value of attribute timeline_max_events.
8 9 10 |
# File 'lib/opentrace/config.rb', line 8 def timeline_max_events @timeline_max_events end |
#timeout ⇒ Object
Returns the value of attribute timeout.
8 9 10 |
# File 'lib/opentrace/config.rb', line 8 def timeout @timeout end |
#trace_propagation ⇒ Object
Returns the value of attribute trace_propagation.
8 9 10 |
# File 'lib/opentrace/config.rb', line 8 def trace_propagation @trace_propagation end |
Instance Method Details
#enabled? ⇒ Boolean
69 70 71 |
# File 'lib/opentrace/config.rb', line 69 def enabled? @enabled && valid? end |
#level_allowed?(level) ⇒ Boolean
77 78 79 80 81 82 83 |
# File 'lib/opentrace/config.rb', line 77 def level_allowed?(level) if allowed_levels allowed_levels.map { |l| l.to_s.upcase }.include?(level.to_s.upcase) else (LEVELS[level.to_s.downcase.to_sym] || 0) >= min_level_value end end |
#logger_severity ⇒ Object
96 97 98 |
# File 'lib/opentrace/config.rb', line 96 def logger_severity LEVEL_TO_LOGGER_SEVERITY[min_level.to_s.downcase.to_sym] || 0 end |
#min_level_value ⇒ Object
73 74 75 |
# File 'lib/opentrace/config.rb', line 73 def min_level_value LEVELS[min_level.to_s.downcase.to_sym] || 0 end |
#valid? ⇒ Boolean
65 66 67 |
# File 'lib/opentrace/config.rb', line 65 def valid? REQUIRED_FIELDS.all? { |f| value = send(f); value.is_a?(String) && !value.empty? } end |