Skip to content

Commit db92d58

Browse files
authored
[log] log(envutil): add debug logging to env var parse fallbacks (#3825)
## Summary Adds debug logging to `internal/envutil/envutil.go` to surface misconfiguration earlier. ## What changed Added `var logEnvUtil = logger.New("envutil:envutil")` and three targeted `logEnvUtil.Printf` calls — one in each type-converting function — that fire only when an environment variable is **set but unusable**: | Function | Log condition | |---|---| | `GetEnvInt` | Value is set but not a valid positive integer | | `GetEnvDuration` | Value is set but not a valid positive duration | | `GetEnvBool` | Value is set but not a recognised boolean (`1/true/yes/on` / `0/false/no/off`) | The `GetEnvString` function is intentionally not logged — it has no parse step and adding a log there would be too noisy. ## Why When an operator sets e.g. `MCP_GATEWAY_PAYLOAD_SIZE_THRESHOLD=512k` (an invalid integer), the gateway silently falls back to the default with no indication of what happened. With this change, enabling `DEBUG=envutil:*` reveals the problem immediately: ``` envutil:envutil GetEnvInt: MCP_GATEWAY_PAYLOAD_SIZE_THRESHOLD="512k" is not a valid positive integer, using default=524288 ``` ## Quality checklist - [x] Exactly 1 file modified - [x] No test files modified - [x] Logger declaration added (`var logEnvUtil = logger.New("envutil:envutil")`) - [x] Logger naming follows `pkg:filename` convention (matches `logGitHub`/`logExpand` in the same package) - [x] Logger arguments use only in-scope variables — no side effects - [x] Log messages are meaningful and actionable - [x] No duplication of existing logs - [x] Import statements follow Go formatting conventions > Generated by [Go Logger Enhancement](https://github.com/github/gh-aw-mcpg/actions/runs/24437444913/agentic_workflow) · ● 4.8M · [◷](https://github.com/search?q=repo%3Agithub%2Fgh-aw-mcpg+%22gh-aw-workflow-id%3A+go-logger%22&type=pullrequests) <!-- gh-aw-agentic-workflow: Go Logger Enhancement, engine: copilot, model: auto, id: 24437444913, workflow_id: go-logger, run: https://github.com/github/gh-aw-mcpg/actions/runs/24437444913 --> <!-- gh-aw-workflow-id: go-logger -->
2 parents f74437c + 9def5d0 commit db92d58

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

internal/envutil/envutil.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@ import (
55
"strconv"
66
"strings"
77
"time"
8+
9+
"github.com/github/gh-aw-mcpg/internal/logger"
10+
"github.com/github/gh-aw-mcpg/internal/logger/sanitize"
811
)
912

13+
var logEnvUtil = logger.New("envutil:envutil")
14+
1015
// GetEnvString returns the value of the environment variable specified by envKey.
1116
// If the environment variable is not set or is empty, it returns the defaultValue.
1217
func GetEnvString(envKey, defaultValue string) string {
@@ -25,18 +30,21 @@ func GetEnvInt(envKey string, defaultValue int) int {
2530
if value, err := strconv.Atoi(envValue); err == nil && value > 0 {
2631
return value
2732
}
33+
logEnvUtil.Printf("GetEnvInt: %s=%q is not a valid positive integer, using default=%d", envKey, sanitize.TruncateSecret(envValue), defaultValue)
2834
}
2935
return defaultValue
3036
}
3137

3238
// GetEnvDuration returns the time.Duration value of the environment variable specified by envKey.
33-
// If the environment variable is not set, is empty, or cannot be parsed by time.ParseDuration,
34-
// it returns the defaultValue. Accepts any string valid for time.ParseDuration (e.g. "2h", "30m", "90s").
39+
// If the environment variable is not set, is empty, cannot be parsed by time.ParseDuration,
40+
// or is not positive (> 0), it returns the defaultValue.
41+
// Accepts any string valid for time.ParseDuration (e.g. "2h", "30m", "90s").
3542
func GetEnvDuration(envKey string, defaultValue time.Duration) time.Duration {
3643
if envValue := os.Getenv(envKey); envValue != "" {
3744
if d, err := time.ParseDuration(envValue); err == nil && d > 0 {
3845
return d
3946
}
47+
logEnvUtil.Printf("GetEnvDuration: %s=%q is not a valid positive duration, using default=%v", envKey, sanitize.TruncateSecret(envValue), defaultValue)
4048
}
4149
return defaultValue
4250
}
@@ -54,6 +62,7 @@ func GetEnvBool(envKey string, defaultValue bool) bool {
5462
case "0", "false", "no", "off":
5563
return false
5664
}
65+
logEnvUtil.Printf("GetEnvBool: %s=%q is not a recognized boolean value, using default=%v", envKey, sanitize.TruncateSecret(envValue), defaultValue)
5766
}
5867
return defaultValue
5968
}

0 commit comments

Comments
 (0)