Skip to content

Commit 26151ec

Browse files
Add debug logging to container detection in sys/container.go
Add a package-level debug logger (logSys) to the sys package following the project's pkg:filename naming convention. Add 4 meaningful debug log calls to IsRunningInContainer() that trace which detection method (dockerenv file, cgroup, or env var) triggered container detection, or confirm when no container environment is found. This helps developers and operators understand container detection behavior at runtime with DEBUG=sys:* or DEBUG=* enabled. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 6470017 commit 26151ec

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

internal/sys/container.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,19 @@ package sys
33
import (
44
"os"
55
"strings"
6+
7+
"github.com/github/gh-aw-mcpg/internal/logger"
68
)
79

10+
var logSys = logger.New("sys:container")
11+
812
// IsRunningInContainer detects if the current process is running inside a container.
913
func IsRunningInContainer() bool {
14+
logSys.Print("Detecting container environment")
15+
1016
// Method 1: Check for /.dockerenv file (Docker-specific)
1117
if _, err := os.Stat("/.dockerenv"); err == nil {
18+
logSys.Print("Container detected via /.dockerenv")
1219
return true
1320
}
1421

@@ -20,14 +27,17 @@ func IsRunningInContainer() bool {
2027
strings.Contains(content, "containerd") ||
2128
strings.Contains(content, "kubepods") ||
2229
strings.Contains(content, "lxc") {
30+
logSys.Print("Container detected via /proc/1/cgroup")
2331
return true
2432
}
2533
}
2634

2735
// Method 3: Check environment variable (set by Dockerfile)
2836
if os.Getenv("RUNNING_IN_CONTAINER") == "true" {
37+
logSys.Print("Container detected via RUNNING_IN_CONTAINER env var")
2938
return true
3039
}
3140

41+
logSys.Print("No container indicators found, running on host")
3242
return false
3343
}

0 commit comments

Comments
 (0)