Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (c *Client) setupTracing() error {
FilterAISpans: c.config.FilterAISpans,
EnableBuiltinAdkTraces: c.config.EnableBuiltinAdkTraces,
SpanFilterFuncs: convertSpanFilters(c.config.SpanFilterFuncs),
EnableConsoleLog: false,
EnableTraceConsoleLog: c.config.EnableTraceConsoleLog,
Exporter: c.config.Exporter,
Logger: c.logger,
}
Expand Down
3 changes: 3 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type Config struct {
// 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
SpanFilterFuncs []SpanFilterFunc
Exporter trace.SpanExporter

Expand All @@ -45,6 +46,7 @@ type SpanFilterFunc func(span trace.ReadOnlySpan) int
// - 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)
func FromEnv() *Config {
Expand All @@ -57,6 +59,7 @@ func FromEnv() *Config {
DefaultProjectName: getEnvString("BRAINTRUST_DEFAULT_PROJECT", "default-go-project"),
BlockingLogin: getEnvBool("BRAINTRUST_BLOCKING_LOGIN", false),
FilterAISpans: getEnvBool("BRAINTRUST_OTEL_FILTER_AI_SPANS", false),
EnableTraceConsoleLog: getEnvBool("BRAINTRUST_ENABLE_TRACE_CONSOLE_LOG", false),
EnableBuiltinAdkTraces: getEnvBool("BRAINTRUST_OTEL_ENABLE_BUILTIN_ADK_TRACES", false),
}
}
Expand Down
3 changes: 3 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func TestFromEnv_Defaults(t *testing.T) {
assert.Equal(t, "default-go-project", cfg.DefaultProjectName)
assert.False(t, cfg.BlockingLogin)
assert.False(t, cfg.FilterAISpans)
assert.False(t, cfg.EnableTraceConsoleLog)
}

func TestFromEnv_LoadsEnvironmentVariables(t *testing.T) {
Expand All @@ -39,6 +40,7 @@ func TestFromEnv_LoadsEnvironmentVariables(t *testing.T) {
t.Setenv("BRAINTRUST_DEFAULT_PROJECT", "my-project")
t.Setenv("BRAINTRUST_BLOCKING_LOGIN", "true")
t.Setenv("BRAINTRUST_OTEL_FILTER_AI_SPANS", "true")
t.Setenv("BRAINTRUST_ENABLE_TRACE_CONSOLE_LOG", "true")

cfg := FromEnv()

Expand All @@ -50,6 +52,7 @@ func TestFromEnv_LoadsEnvironmentVariables(t *testing.T) {
assert.Equal(t, "my-project", cfg.DefaultProjectName)
assert.True(t, cfg.BlockingLogin)
assert.True(t, cfg.FilterAISpans)
assert.True(t, cfg.EnableTraceConsoleLog)
}

func TestFromEnv_TrimsWhitespace(t *testing.T) {
Expand Down
8 changes: 8 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ func WithExporter(exporter trace.SpanExporter) Option {
}
}

// WithEnableTraceConsoleLog enables logging traces to stdout for debugging.
// Environment variable: BRAINTRUST_ENABLE_TRACE_CONSOLE_LOG
func WithEnableTraceConsoleLog(enabled bool) Option {
return func(c *config.Config) {
c.EnableTraceConsoleLog = enabled
}
}

// WithFilterAISpans enables filtering to keep only AI-related spans
// When enabled, only spans with AI-related names or attributes will be sent
func WithFilterAISpans(enabled bool) Option {
Expand Down
4 changes: 2 additions & 2 deletions trace/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type Config struct {
SpanFilterFuncs []SpanFilterFunc

// Debug
EnableConsoleLog bool
EnableTraceConsoleLog bool

// Test override: provide custom exporter (e.g., memory exporter for tests)
Exporter sdktrace.SpanExporter
Expand Down Expand Up @@ -154,7 +154,7 @@ func AddSpanProcessor(tp *sdktrace.TracerProvider, session *auth.Session, cfg Co
log.Debug("registered Braintrust span processor")

// Add console log processor if requested
if cfg.EnableConsoleLog {
if cfg.EnableTraceConsoleLog {
consoleExporter, err := stdouttrace.New(stdouttrace.WithPrettyPrint())
if err == nil {
tp.RegisterSpanProcessor(sdktrace.NewBatchSpanProcessor(consoleExporter))
Expand Down
Loading