Class: Traces::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/traces/config.rb

Overview

Represents a configuration for the traces library.

Constant Summary collapse

DEFAULT_PATH =
ENV.fetch("TRACES_CONFIG_DEFAULT_PATH", "config/traces.rb")
DEFAULT =

Load the default configuration.

self.default

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.defaultObject

Load the default configuration.



26
27
28
# File 'lib/traces/config.rb', line 26

def self.default
	@default ||= self.load(DEFAULT_PATH)
end

.load(path) ⇒ Object

Load the configuration from the given path.



14
15
16
17
18
19
20
21
22
# File 'lib/traces/config.rb', line 14

def self.load(path)
	config = self.new
	
	if File.exist?(path)
		config.instance_eval(File.read(path), path)
	end
	
	return config
end

Instance Method Details

#prepareObject

Prepare the backend, e.g. by loading additional libraries or instrumentation.



31
32
# File 'lib/traces/config.rb', line 31

def prepare
end

#require_backend(env = ENV) ⇒ Object

Require a specific traces backend implementation.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/traces/config.rb', line 35

def require_backend(env = ENV)
	if backend = env["TRACES_BACKEND"]
		begin
			require(backend)
			
			# We ensure that the interface methods replace any existing methods by prepending the module:
			Traces.singleton_class.prepend(Backend::Interface)
			
			return true
		rescue LoadError => error
			warn "Unable to load traces backend: #{backend.inspect}!"
		end
	end
	
	return false
end