Module: Braintrust::Internal::Env

Defined in:
lib/braintrust/internal/env.rb

Overview

Environment variable utilities.

Constant Summary collapse

ENV_AUTO_INSTRUMENT =
"BRAINTRUST_AUTO_INSTRUMENT"
ENV_INSTRUMENT_EXCEPT =
"BRAINTRUST_INSTRUMENT_EXCEPT"
ENV_INSTRUMENT_ONLY =
"BRAINTRUST_INSTRUMENT_ONLY"
ENV_FLUSH_ON_EXIT =
"BRAINTRUST_FLUSH_ON_EXIT"

Class Method Summary collapse

Class Method Details

.auto_instrumentObject



12
13
14
# File 'lib/braintrust/internal/env.rb', line 12

def self.auto_instrument
  ENV[ENV_AUTO_INSTRUMENT] != "false"
end

.flush_on_exitObject

Whether to automatically flush spans on program exit. Default: true



17
18
19
# File 'lib/braintrust/internal/env.rb', line 17

def self.flush_on_exit
  ENV[ENV_FLUSH_ON_EXIT] != "false"
end

.instrument_exceptObject



21
22
23
# File 'lib/braintrust/internal/env.rb', line 21

def self.instrument_except
  parse_list(ENV_INSTRUMENT_EXCEPT)
end

.instrument_onlyObject



25
26
27
# File 'lib/braintrust/internal/env.rb', line 25

def self.instrument_only
  parse_list(ENV_INSTRUMENT_ONLY)
end

.parse_list(key) ⇒ Array<Symbol>?

Parse a comma-separated environment variable into an array of symbols.

Parameters:

  • key (String)

    The environment variable name

Returns:

  • (Array<Symbol>, nil)

    Array of symbols, or nil if not set



32
33
34
35
36
# File 'lib/braintrust/internal/env.rb', line 32

def self.parse_list(key)
  value = ENV[key]
  return nil unless value
  value.split(",").map(&:strip).map(&:to_sym)
end