Class: OpenTrace::Config

Inherits:
Object
  • Object
show all
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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/opentrace/config.rb', line 14

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
  @hostname       = nil
  @pid            = nil
  @git_sha        = nil
  @batch_size     = 50
  @flush_interval = 5.0
  @sql_logging    = true
  @sql_duration_threshold_ms = 0.0
  @ignore_paths   = []
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



8
9
10
# File 'lib/opentrace/config.rb', line 8

def api_key
  @api_key
end

#batch_sizeObject

Returns the value of attribute batch_size.



8
9
10
# File 'lib/opentrace/config.rb', line 8

def batch_size
  @batch_size
end

#contextObject

Returns the value of attribute context.



8
9
10
# File 'lib/opentrace/config.rb', line 8

def context
  @context
end

#enabledObject

Returns the value of attribute enabled.



8
9
10
# File 'lib/opentrace/config.rb', line 8

def enabled
  @enabled
end

#endpointObject

Returns the value of attribute endpoint.



8
9
10
# File 'lib/opentrace/config.rb', line 8

def endpoint
  @endpoint
end

#environmentObject

Returns the value of attribute environment.



8
9
10
# File 'lib/opentrace/config.rb', line 8

def environment
  @environment
end

#flush_intervalObject

Returns the value of attribute flush_interval.



8
9
10
# File 'lib/opentrace/config.rb', line 8

def flush_interval
  @flush_interval
end

#git_shaObject

Returns the value of attribute git_sha.



8
9
10
# File 'lib/opentrace/config.rb', line 8

def git_sha
  @git_sha
end

#hostnameObject

Returns the value of attribute hostname.



8
9
10
# File 'lib/opentrace/config.rb', line 8

def hostname
  @hostname
end

#ignore_pathsObject

Returns the value of attribute ignore_paths.



8
9
10
# File 'lib/opentrace/config.rb', line 8

def ignore_paths
  @ignore_paths
end

#min_levelObject

Returns the value of attribute min_level.



8
9
10
# File 'lib/opentrace/config.rb', line 8

def min_level
  @min_level
end

#pidObject

Returns the value of attribute pid.



8
9
10
# File 'lib/opentrace/config.rb', line 8

def pid
  @pid
end

#serviceObject

Returns the value of attribute service.



8
9
10
# File 'lib/opentrace/config.rb', line 8

def service
  @service
end

#sql_duration_threshold_msObject

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_loggingObject

Returns the value of attribute sql_logging.



8
9
10
# File 'lib/opentrace/config.rb', line 8

def sql_logging
  @sql_logging
end

#timeoutObject

Returns the value of attribute timeout.



8
9
10
# File 'lib/opentrace/config.rb', line 8

def timeout
  @timeout
end

Instance Method Details

#enabled?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/opentrace/config.rb', line 37

def enabled?
  @enabled && valid?
end

#min_level_valueObject



41
42
43
# File 'lib/opentrace/config.rb', line 41

def min_level_value
  LEVELS[min_level.to_s.downcase.to_sym] || 0
end

#valid?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/opentrace/config.rb', line 33

def valid?
  REQUIRED_FIELDS.all? { |f| value = send(f); value.is_a?(String) && !value.empty? }
end