config

package
v0.19.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 8 Imported by: 2 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

type APIKeyResolver interface {
	APIKey(context.Context) (string, bool)
}

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)

func (*Config) IsValid

func (c *Config) IsValid() error

IsValid checks if the configuration has all required fields. Returns an error if any required field is missing.

type Environment added in v0.10.0

type Environment struct {
	Type string
	Name string
}

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 stop later hooks for that span and strip its content,
	// retaining original IDs, timestamps, protocol flags, and braintrust.parent routing.
	// braintrust.context_json is replaced with {"customizer_error":true}. Stripped spans
	// upload no attachments; they and unrelated spans continue through export.
	// Hook failures log at most once per process, without hook error text or payloads.
	// Submitting a batch again invokes hooks again; transport retries reuse the result.
	//
	// 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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL