Skip to content

Commit 4e6142c

Browse files
clutchskiclaudeAbhiPrasad
authored
fix: restore BRAINTRUST_ENABLE_TRACE_CONSOLE_LOG support lost in v0.1 migration (#67)
The v0.1 API migration (59f102a) deleted the old env.go which read this env var, but the new config/config.go never re-added it. The trace layer still had the implementation but client.go hardcoded it to false. - Add EnableTraceConsoleLog field to config.Config - Read BRAINTRUST_ENABLE_TRACE_CONSOLE_LOG env var in FromEnv() - Add WithEnableTraceConsoleLog option - Wire config value through client.go instead of hardcoding false - Rename trace.Config.EnableConsoleLog to EnableTraceConsoleLog for consistency Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: Abhijeet Prasad <abhijeet@braintrustdata.com>
1 parent c39afdb commit 4e6142c

5 files changed

Lines changed: 17 additions & 3 deletions

File tree

client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func (c *Client) setupTracing() error {
121121
FilterAISpans: c.config.FilterAISpans,
122122
EnableBuiltinAdkTraces: c.config.EnableBuiltinAdkTraces,
123123
SpanFilterFuncs: convertSpanFilters(c.config.SpanFilterFuncs),
124-
EnableConsoleLog: false,
124+
EnableTraceConsoleLog: c.config.EnableTraceConsoleLog,
125125
Exporter: c.config.Exporter,
126126
Logger: c.logger,
127127
}

config/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type Config struct {
2424
// Tracing configuration
2525
FilterAISpans bool
2626
EnableBuiltinAdkTraces bool // if false (default), drop Google ADK native spans to avoid duplicates
27+
EnableTraceConsoleLog bool // log traces to stdout for debugging
2728
SpanFilterFuncs []SpanFilterFunc
2829
Exporter trace.SpanExporter
2930

@@ -45,6 +46,7 @@ type SpanFilterFunc func(span trace.ReadOnlySpan) int
4546
// - BRAINTRUST_DEFAULT_PROJECT_ID: Default project ID
4647
// - BRAINTRUST_DEFAULT_PROJECT: Default project name (default: "default-go-project")
4748
// - BRAINTRUST_BLOCKING_LOGIN: Enable blocking login (default: false)
49+
// - BRAINTRUST_ENABLE_TRACE_CONSOLE_LOG: Log traces to stdout for debugging (default: false)
4850
// - BRAINTRUST_OTEL_FILTER_AI_SPANS: Filter to keep only AI-related spans (default: false)
4951
// - BRAINTRUST_OTEL_ENABLE_BUILTIN_ADK_TRACES: Enable exporting spans from Google ADK's built-in telemetry (default: false)
5052
func FromEnv() *Config {
@@ -57,6 +59,7 @@ func FromEnv() *Config {
5759
DefaultProjectName: getEnvString("BRAINTRUST_DEFAULT_PROJECT", "default-go-project"),
5860
BlockingLogin: getEnvBool("BRAINTRUST_BLOCKING_LOGIN", false),
5961
FilterAISpans: getEnvBool("BRAINTRUST_OTEL_FILTER_AI_SPANS", false),
62+
EnableTraceConsoleLog: getEnvBool("BRAINTRUST_ENABLE_TRACE_CONSOLE_LOG", false),
6063
EnableBuiltinAdkTraces: getEnvBool("BRAINTRUST_OTEL_ENABLE_BUILTIN_ADK_TRACES", false),
6164
}
6265
}

config/config_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ func TestFromEnv_Defaults(t *testing.T) {
2727
assert.Equal(t, "default-go-project", cfg.DefaultProjectName)
2828
assert.False(t, cfg.BlockingLogin)
2929
assert.False(t, cfg.FilterAISpans)
30+
assert.False(t, cfg.EnableTraceConsoleLog)
3031
}
3132

3233
func TestFromEnv_LoadsEnvironmentVariables(t *testing.T) {
@@ -39,6 +40,7 @@ func TestFromEnv_LoadsEnvironmentVariables(t *testing.T) {
3940
t.Setenv("BRAINTRUST_DEFAULT_PROJECT", "my-project")
4041
t.Setenv("BRAINTRUST_BLOCKING_LOGIN", "true")
4142
t.Setenv("BRAINTRUST_OTEL_FILTER_AI_SPANS", "true")
43+
t.Setenv("BRAINTRUST_ENABLE_TRACE_CONSOLE_LOG", "true")
4244

4345
cfg := FromEnv()
4446

@@ -50,6 +52,7 @@ func TestFromEnv_LoadsEnvironmentVariables(t *testing.T) {
5052
assert.Equal(t, "my-project", cfg.DefaultProjectName)
5153
assert.True(t, cfg.BlockingLogin)
5254
assert.True(t, cfg.FilterAISpans)
55+
assert.True(t, cfg.EnableTraceConsoleLog)
5356
}
5457

5558
func TestFromEnv_TrimsWhitespace(t *testing.T) {

options.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ func WithExporter(exporter trace.SpanExporter) Option {
8080
}
8181
}
8282

83+
// WithEnableTraceConsoleLog enables logging traces to stdout for debugging.
84+
// Environment variable: BRAINTRUST_ENABLE_TRACE_CONSOLE_LOG
85+
func WithEnableTraceConsoleLog(enabled bool) Option {
86+
return func(c *config.Config) {
87+
c.EnableTraceConsoleLog = enabled
88+
}
89+
}
90+
8391
// WithFilterAISpans enables filtering to keep only AI-related spans
8492
// When enabled, only spans with AI-related names or attributes will be sent
8593
func WithFilterAISpans(enabled bool) Option {

trace/trace.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ type Config struct {
5555
SpanFilterFuncs []SpanFilterFunc
5656

5757
// Debug
58-
EnableConsoleLog bool
58+
EnableTraceConsoleLog bool
5959

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

156156
// Add console log processor if requested
157-
if cfg.EnableConsoleLog {
157+
if cfg.EnableTraceConsoleLog {
158158
consoleExporter, err := stdouttrace.New(stdouttrace.WithPrettyPrint())
159159
if err == nil {
160160
tp.RegisterSpanProcessor(sdktrace.NewBatchSpanProcessor(consoleExporter))

0 commit comments

Comments
 (0)