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.



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

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
  @sdk_version    = NurseAndrea::VERSION
  @sdk_language   = "ruby"
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

#sdk_languageObject

Returns the value of attribute sdk_language.



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

def sdk_language
  @sdk_language
end

#sdk_versionObject

Returns the value of attribute sdk_version.



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

def sdk_version
  @sdk_version
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)


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

def enabled?
  @enabled
end

#handshake_urlObject



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

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

#ingest_urlObject

All endpoint URLs derived from host



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

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

#metrics_urlObject



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

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

#min_log_level_intObject



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

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

#traces_urlObject



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

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

#valid?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/nurse_andrea/configuration.rb', line 43

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

#validate!Object



47
48
49
50
51
52
53
54
55
# File 'lib/nurse_andrea/configuration.rb', line 47

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