Module: Dash0::OpenTelemetry::Environment

Defined in:
lib/dash0/opentelemetry/environment.rb

Overview

Helpers for reading and defaulting environment variables. The distribution is configured entirely through the environment (DASH0_* switches and standard OTEL_* variables).

Class Method Summary collapse

Class Method Details

.debug?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/dash0/opentelemetry/environment.rb', line 48

def debug?
  opted_in?('DASH0_DEBUG')
end

.integer(name, default) ⇒ Object

Parses an integer environment variable, falling back to default when unset or not a valid integer.



39
40
41
42
43
44
45
46
# File 'lib/dash0/opentelemetry/environment.rb', line 39

def integer(name, default)
  value = ENV.fetch(name, nil)
  return default if value.nil? || value.strip.empty?

  Integer(value.strip)
rescue ArgumentError
  default
end

.opted_in?(name) ⇒ Boolean

True when the variable is set to "true" (case-insensitive, trimmed).

Returns:

  • (Boolean)


15
16
17
# File 'lib/dash0/opentelemetry/environment.rb', line 15

def opted_in?(name)
  ENV.fetch(name, '').strip.casecmp('true').zero?
end

.opted_out?(name) ⇒ Boolean

True when the variable is set to "false" (case-insensitive, trimmed).

Returns:

  • (Boolean)


20
21
22
# File 'lib/dash0/opentelemetry/environment.rb', line 20

def opted_out?(name)
  ENV.fetch(name, '').strip.casecmp('false').zero?
end

.present?(name) ⇒ Boolean

True when the variable is set to a non-empty (trimmed) value.

Returns:

  • (Boolean)


25
26
27
28
# File 'lib/dash0/opentelemetry/environment.rb', line 25

def present?(name)
  value = ENV.fetch(name, nil)
  !value.nil? && !value.strip.empty?
end

.set_default(name, value) ⇒ Object

Sets name to value unless it already has a non-empty value. This lets the distribution provide defaults without ever overriding a value the application or operator set explicitly.



33
34
35
# File 'lib/dash0/opentelemetry/environment.rb', line 33

def set_default(name, value)
  ENV[name] = value unless present?(name)
end