Class: Tracelit::Configuration

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



31
32
33
34
35
36
37
38
39
# File 'lib/tracelit/configuration.rb', line 31

def initialize
  @api_key            = ENV["TRACELIT_API_KEY"]
  @service_name       = ENV["TRACELIT_SERVICE_NAME"]
  @environment        = ENV["TRACELIT_ENVIRONMENT"] || "production"
  @endpoint           = ENV["TRACELIT_ENDPOINT"]    || "https://ingest.tracelit.app"
  @sample_rate        = (ENV["TRACELIT_SAMPLE_RATE"] || "1.0").to_f
  @enabled            = ENV["TRACELIT_ENABLED"] != "false"
  @resource_attributes = {}
end

Instance Attribute Details

#api_keyObject

Required



6
7
8
# File 'lib/tracelit/configuration.rb', line 6

def api_key
  @api_key
end

#enabledObject

Set false to disable all telemetry without removing the gem. Useful for test environments.



25
26
27
# File 'lib/tracelit/configuration.rb', line 25

def enabled
  @enabled
end

#endpointObject

Full URL of the Tracelit ingest endpoint. Override only if self-hosting.



17
18
19
# File 'lib/tracelit/configuration.rb', line 17

def endpoint
  @endpoint
end

#environmentObject

Environment tag — production, staging, development, etc.



13
14
15
# File 'lib/tracelit/configuration.rb', line 13

def environment
  @environment
end

#resource_attributesObject

Additional resource attributes appended to every span and log. Hash of string keys and string values.



29
30
31
# File 'lib/tracelit/configuration.rb', line 29

def resource_attributes
  @resource_attributes
end

#sample_rateObject

Head-based sampling rate (0.0–1.0). Default: 1.0 (keep all traces). Set to 0.1 to keep 10% of traces. Errors are always kept regardless.



21
22
23
# File 'lib/tracelit/configuration.rb', line 21

def sample_rate
  @sample_rate
end

#service_nameObject

The name of this service as it will appear in Tracelit. Defaults to the Rails app name if Rails is present.



10
11
12
# File 'lib/tracelit/configuration.rb', line 10

def service_name
  @service_name
end

Instance Method Details

#resolved_service_nameObject

Infer service name from Rails application if not explicitly set.



48
49
50
51
52
# File 'lib/tracelit/configuration.rb', line 48

def resolved_service_name
  return service_name if service_name && !service_name.empty?
  return ::Rails.application.class.module_parent_name.underscore if defined?(::Rails)
  "unknown-service"
end

#validate!Object

Raises:

  • (ArgumentError)


41
42
43
44
45
# File 'lib/tracelit/configuration.rb', line 41

def validate!
  raise ArgumentError, "Tracelit.config.api_key is required" if api_key.nil? || api_key.empty?
  raise ArgumentError, "Tracelit.config.service_name is required" if service_name.nil? || service_name.empty?
  raise ArgumentError, "sample_rate must be between 0.0 and 1.0" unless sample_rate.between?(0.0, 1.0)
end