From 8955b57ddc45c0f0a08af251aaa10fb6abc950d2 Mon Sep 17 00:00:00 2001 From: Codex Local Date: Wed, 26 Aug 2026 10:51:33 +0800 Subject: [PATCH] fix: allow disabling trace export --- internal/config/config.go | 10 +++++++++- internal/config/config_test.go | 11 +++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/internal/config/config.go b/internal/config/config.go index a16b2ba..e77d7dc 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -269,7 +269,7 @@ func Load(serviceName string) (Config, error) { AuthIssuerURL: stringEnv("AUTH_ISSUER_URL", "http://localhost:58180/realms/voice-local"), AuthJWKSURL: stringEnv("AUTH_JWKS_URL", "http://localhost:58180/realms/voice-local/protocol/openid-connect/certs"), AuthAudience: stringEnv("AUTH_AUDIENCE", "voice-platform-web"), - OTLPEndpoint: stringEnv("OTEL_EXPORTER_OTLP_ENDPOINT", "localhost:54317"), + OTLPEndpoint: stringEnvAllowEmpty("OTEL_EXPORTER_OTLP_ENDPOINT", "localhost:54317"), DependencyTimeout: dependencyTimeout, ExternalProbeInterval: externalProbeInterval, ShutdownTimeout: shutdownTimeout, @@ -703,6 +703,14 @@ func stringEnv(key, fallback string) string { return value } +func stringEnvAllowEmpty(key, fallback string) string { + value, exists := os.LookupEnv(key) + if !exists { + return fallback + } + return strings.TrimSpace(value) +} + func intEnv(key string, fallback int) (int, error) { value := strings.TrimSpace(os.Getenv(key)) if value == "" { diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 13f8461..cb42998 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -27,6 +27,17 @@ func TestLoadUsesServicePortDefaults(t *testing.T) { } } +func TestLoadAllowsTracingExporterToBeDisabled(t *testing.T) { + t.Setenv("OTEL_EXPORTER_OTLP_ENDPOINT", "") + cfg, err := Load("api") + if err != nil { + t.Fatal(err) + } + if cfg.OTLPEndpoint != "" { + t.Fatalf("OTLPEndpoint = %q, want disabled exporter", cfg.OTLPEndpoint) + } +} + func TestLoadRejectsInvalidDuration(t *testing.T) { t.Setenv("DEPENDENCY_TIMEOUT", "soon") if _, err := Load("api"); err == nil {