Class: Braintrust::Config
- Inherits:
-
Object
- Object
- Braintrust::Config
- Defined in:
- lib/braintrust/config.rb
Overview
Configuration object that reads from environment variables and allows overriding with explicit options
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#api_url ⇒ Object
readonly
Returns the value of attribute api_url.
-
#app_url ⇒ Object
readonly
Returns the value of attribute app_url.
-
#default_project ⇒ Object
readonly
Returns the value of attribute default_project.
-
#filter_ai_spans ⇒ Object
readonly
Returns the value of attribute filter_ai_spans.
-
#org_name ⇒ Object
readonly
Returns the value of attribute org_name.
-
#span_filter_funcs ⇒ Object
readonly
Returns the value of attribute span_filter_funcs.
Class Method Summary collapse
-
.from_env(api_key: nil, org_name: nil, default_project: nil, app_url: nil, api_url: nil, filter_ai_spans: nil, span_filter_funcs: nil) ⇒ Config
Create a Config from environment variables, with option overrides Passed-in options take priority over ENV vars.
Instance Method Summary collapse
-
#initialize(api_key: nil, org_name: nil, default_project: nil, app_url: nil, api_url: nil, filter_ai_spans: nil, span_filter_funcs: nil) ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize(api_key: nil, org_name: nil, default_project: nil, app_url: nil, api_url: nil, filter_ai_spans: nil, span_filter_funcs: nil) ⇒ Config
Returns a new instance of Config.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/braintrust/config.rb', line 10 def initialize(api_key: nil, org_name: nil, default_project: nil, app_url: nil, api_url: nil, filter_ai_spans: nil, span_filter_funcs: nil) @api_key = api_key @org_name = org_name @default_project = default_project @app_url = app_url @api_url = api_url @filter_ai_spans = filter_ai_spans @span_filter_funcs = span_filter_funcs || [] end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
7 8 9 |
# File 'lib/braintrust/config.rb', line 7 def api_key @api_key end |
#api_url ⇒ Object (readonly)
Returns the value of attribute api_url.
7 8 9 |
# File 'lib/braintrust/config.rb', line 7 def api_url @api_url end |
#app_url ⇒ Object (readonly)
Returns the value of attribute app_url.
7 8 9 |
# File 'lib/braintrust/config.rb', line 7 def app_url @app_url end |
#default_project ⇒ Object (readonly)
Returns the value of attribute default_project.
7 8 9 |
# File 'lib/braintrust/config.rb', line 7 def default_project @default_project end |
#filter_ai_spans ⇒ Object (readonly)
Returns the value of attribute filter_ai_spans.
7 8 9 |
# File 'lib/braintrust/config.rb', line 7 def filter_ai_spans @filter_ai_spans end |
#org_name ⇒ Object (readonly)
Returns the value of attribute org_name.
7 8 9 |
# File 'lib/braintrust/config.rb', line 7 def org_name @org_name end |
#span_filter_funcs ⇒ Object (readonly)
Returns the value of attribute span_filter_funcs.
7 8 9 |
# File 'lib/braintrust/config.rb', line 7 def span_filter_funcs @span_filter_funcs end |
Class Method Details
.from_env(api_key: nil, org_name: nil, default_project: nil, app_url: nil, api_url: nil, filter_ai_spans: nil, span_filter_funcs: nil) ⇒ Config
Create a Config from environment variables, with option overrides Passed-in options take priority over ENV vars
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/braintrust/config.rb', line 31 def self.from_env(api_key: nil, org_name: nil, default_project: nil, app_url: nil, api_url: nil, filter_ai_spans: nil, span_filter_funcs: nil) # Parse filter_ai_spans from ENV if not explicitly provided env_filter_ai_spans = ENV["BRAINTRUST_OTEL_FILTER_AI_SPANS"] filter_ai_spans_value = if filter_ai_spans.nil? env_filter_ai_spans&.downcase == "true" else filter_ai_spans end new( api_key: api_key || ((ENV["BRAINTRUST_API_KEY"] && ENV["BRAINTRUST_API_KEY"].empty?) ? nil : ENV["BRAINTRUST_API_KEY"]), org_name: org_name || ENV["BRAINTRUST_ORG_NAME"], default_project: default_project || ENV["BRAINTRUST_DEFAULT_PROJECT"], app_url: app_url || ENV["BRAINTRUST_APP_URL"] || "https://www.braintrust.dev", api_url: api_url || ENV["BRAINTRUST_API_URL"] || "https://api.braintrust.dev", filter_ai_spans: filter_ai_spans_value, span_filter_funcs: span_filter_funcs ) end |