Documentation
¶
Overview ¶
Package config provides configuration management for the Braintrust SDK.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIKeyResolver ¶ added in v0.8.0
APIKeyResolver resolves a Braintrust API key when one is not provided explicitly or through the process environment.
type Config ¶
type Config struct {
APIKey string
APIKeyResolver APIKeyResolver
APIURL string
AppURL string
OrgName string
DefaultProjectID string
DefaultProjectName string
BlockingLogin bool
// Tracing configuration
FilterAISpans bool
EnableBuiltinAdkTraces bool // if false (default), drop Google ADK native spans to avoid duplicates
EnableTraceConsoleLog bool // log traces to stdout for debugging
AutoConvertAIAttachments bool // scan spans for base64 attachments and upload them (default: true)
SpanFilterFuncs []SpanFilterFunc
SpanCustomizers []SpanCustomizer
Exporter trace.SpanExporter
Environment *Environment
// Logger
Logger logger.Logger
}
Config holds immutable configuration for the Braintrust SDK.
func FromEnv ¶
func FromEnv() *Config
FromEnv loads configuration from environment variables with defaults. If BRAINTRUST_API_KEY is unset or blank, API key discovery can fall back to the nearest .braintrust.json file when authentication or export first needs it.
Supported environment variables:
- BRAINTRUST_API_KEY: API key for authentication
- BRAINTRUST_API_URL: API endpoint URL (default: "https://api.braintrust.dev")
- BRAINTRUST_APP_URL: Application URL (default: "https://www.braintrust.dev")
- BRAINTRUST_ORG_NAME: Organization name
- BRAINTRUST_DEFAULT_PROJECT_ID: Default project ID
- BRAINTRUST_DEFAULT_PROJECT: Default project name (default: "default-go-project")
- BRAINTRUST_BLOCKING_LOGIN: Enable blocking login (default: false)
- BRAINTRUST_ENABLE_TRACE_CONSOLE_LOG: Log traces to stdout for debugging (default: false)
- BRAINTRUST_OTEL_FILTER_AI_SPANS: Filter to keep only AI-related spans (default: false)
- BRAINTRUST_OTEL_ENABLE_BUILTIN_ADK_TRACES: Enable exporting spans from Google ADK's built-in telemetry (default: false)
- BRAINTRUST_AUTO_CONVERT_AI_ATTACHMENTS: Scan spans for base64 attachments and upload them (default: true)
type Environment ¶ added in v0.10.0
Environment describes where spans are produced for span-origin provenance.
func DetectEnvironment ¶ added in v0.10.0
func DetectEnvironment(explicit *Environment) *Environment
DetectEnvironment resolves span-origin environment provenance from an explicit value, Braintrust environment variables, CI, and server runtimes.
type SpanCustomizer ¶ added in v0.16.0
type SpanCustomizer struct {
// OnSpanExport synchronously transforms a completed export snapshot. Return the
// original span or a replacement embedding sdktrace.ReadOnlySpan; nil (including
// typed nil) is not a way to drop spans. Trace/span IDs and parent trace/span IDs
// must be preserved. Attributes, including braintrust.parent routing, may change.
//
// Hooks run in registration order for every span reaching the Braintrust exporter,
// after filtering, before automatic attachment processing/uploads and serialization.
// Remove or redact inline attachments here to prevent their upload. Errors, panics,
// nil results, or changed IDs fail the entire batch before any spans or attachments are sent.
// Submitting a batch again invokes hooks again; transport retries do not.
//
// Hooks may run on background goroutines and should be fast and concurrency-safe.
// Do not retain or asynchronously mutate the supplied span or returned replacement.
OnSpanExport func(span trace.ReadOnlySpan) (trace.ReadOnlySpan, error)
}
SpanCustomizer transforms outgoing telemetry without changing application spans. Hooks are optional; a zero-value customizer is a no-op. Use keyed struct literals so future optional hooks can be added without changing existing registrations.
type SpanFilterFunc ¶
type SpanFilterFunc func(span trace.ReadOnlySpan) int
SpanFilterFunc is a function that decides which spans to send to Braintrust. Return >0 to keep the span, <0 to drop the span, or 0 to not influence the decision.