Class: NurseAndrea::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/nurse_andrea/configuration.rb

Constant Summary collapse

LOG_LEVELS =
{ debug: 0, info: 1, warn: 2, error: 3, fatal: 4 }.freeze
DEFAULT_HOST =
"https://nurseandrea.io"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/nurse_andrea/configuration.rb', line 10

def initialize
  @host           = DEFAULT_HOST
  @timeout        = 5
  @log_level      = :debug
  @batch_size     = 100
  @flush_interval = 10
  @backfill_hours = 24
  @log_file_path  = nil
  @enabled        = true
  @debug          = false
  @service_name   = default_service_name
end

Instance Attribute Details

#api_keyObject Also known as: token

Returns the value of attribute api_key.



3
4
5
# File 'lib/nurse_andrea/configuration.rb', line 3

def api_key
  @api_key
end

#backfill_hoursObject

Returns the value of attribute backfill_hours.



3
4
5
# File 'lib/nurse_andrea/configuration.rb', line 3

def backfill_hours
  @backfill_hours
end

#batch_sizeObject

Returns the value of attribute batch_size.



3
4
5
# File 'lib/nurse_andrea/configuration.rb', line 3

def batch_size
  @batch_size
end

#debugObject

Returns the value of attribute debug.



3
4
5
# File 'lib/nurse_andrea/configuration.rb', line 3

def debug
  @debug
end

#enabledObject

Returns the value of attribute enabled.



3
4
5
# File 'lib/nurse_andrea/configuration.rb', line 3

def enabled
  @enabled
end

#flush_intervalObject

Returns the value of attribute flush_interval.



3
4
5
# File 'lib/nurse_andrea/configuration.rb', line 3

def flush_interval
  @flush_interval
end

#hostObject

Returns the value of attribute host.



3
4
5
# File 'lib/nurse_andrea/configuration.rb', line 3

def host
  @host
end

#log_file_pathObject

Returns the value of attribute log_file_path.



3
4
5
# File 'lib/nurse_andrea/configuration.rb', line 3

def log_file_path
  @log_file_path
end

#log_levelObject

Returns the value of attribute log_level.



3
4
5
# File 'lib/nurse_andrea/configuration.rb', line 3

def log_level
  @log_level
end

#service_nameObject

Returns the value of attribute service_name.



3
4
5
# File 'lib/nurse_andrea/configuration.rb', line 3

def service_name
  @service_name
end

#timeoutObject

Returns the value of attribute timeout.



3
4
5
# File 'lib/nurse_andrea/configuration.rb', line 3

def timeout
  @timeout
end

Instance Method Details

#enabled?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/nurse_andrea/configuration.rb', line 32

def enabled?
  @enabled
end

#handshake_urlObject



30
# File 'lib/nurse_andrea/configuration.rb', line 30

def handshake_url = "#{normalised_host}/api/v1/handshake"

#ingest_urlObject

All endpoint URLs derived from host



27
# File 'lib/nurse_andrea/configuration.rb', line 27

def ingest_url    = "#{normalised_host}/api/v1/ingest"

#metrics_urlObject



28
# File 'lib/nurse_andrea/configuration.rb', line 28

def metrics_url   = "#{normalised_host}/api/v1/metrics"

#min_log_level_intObject



36
37
38
# File 'lib/nurse_andrea/configuration.rb', line 36

def min_log_level_int
  LOG_LEVELS.fetch(log_level.to_sym, 0)
end

#traces_urlObject



29
# File 'lib/nurse_andrea/configuration.rb', line 29

def traces_url    = "#{normalised_host}/api/v1/traces"

#valid?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/nurse_andrea/configuration.rb', line 40

def valid?
  !api_key.nil? && !api_key.to_s.strip.empty? && !host.nil?
end

#validate!Object



44
45
46
47
48
49
50
51
52
# File 'lib/nurse_andrea/configuration.rb', line 44

def validate!
  unless valid?
    raise NurseAndrea::ConfigurationError,
      "[NurseAndrea] Configuration invalid. " \
      "Set NURSE_ANDREA_TOKEN and NURSE_ANDREA_HOST, then call " \
      "NurseAndrea.configure in config/initializers/nurse_andrea.rb"
  end
  self
end