Skip to content

[log] Add debug logging to container detection in sys/container.go#2598

Merged
lpcox merged 1 commit intomainfrom
log/sys-container-detection-bcc7f338a15d6855
Mar 26, 2026
Merged

[log] Add debug logging to container detection in sys/container.go#2598
lpcox merged 1 commit intomainfrom
log/sys-container-detection-bcc7f338a15d6855

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

Summary

Adds a package-level debug logger (logSys) and 4 meaningful debug log calls to internal/sys/container.go, following the project's pkg:filename naming convention from AGENTS.md.

Changes

File modified: internal/sys/container.go

What was added

  1. Import for github.com/github/gh-aw-mcpg/internal/logger
  2. Package-level logger variable: var logSys = logger.New("sys:container")
  3. Debug log at function entry: "Detecting container environment"
  4. Detection method trace logs for each of the 3 detection paths:
    • "Container detected via /.dockerenv" (Method 1)
    • "Container detected via /proc/1/cgroup" (Method 2)
    • "Container detected via RUNNING_IN_CONTAINER env var" (Method 3)
  5. Fallback log: "No container indicators found, running on host"

Why this is useful

IsRunningInContainer() is a critical detection function used to determine execution context and control security behavior (e.g., whether direct command execution is permitted). When troubleshooting container detection issues, developers had no visibility into which detection method triggered (or why detection failed). With this change, running DEBUG=sys:* ./awmg --config config.toml reveals exactly which method fires.

Quality checklist

  • Exactly 1 file modified
  • No test files modified
  • Logger declaration added following pkg:filename convention (sys:container)
  • Log arguments are all string literals (no side effects)
  • Messages are meaningful and actionable for debugging
  • No duplicate logging with existing logs
  • Import statements properly formatted
  • Naming follows project convention (logSys matches logConn, logSchema, etc.)

Generated by Go Logger Enhancement ·

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>
@github-actions github-actions bot added automation enhancement New feature or request labels Mar 26, 2026
@lpcox lpcox marked this pull request as ready for review March 26, 2026 23:12
Copilot AI review requested due to automatic review settings March 26, 2026 23:12
@lpcox lpcox merged commit 0d4e760 into main Mar 26, 2026
3 checks passed
@lpcox lpcox deleted the log/sys-container-detection-bcc7f338a15d6855 branch March 26, 2026 23:12
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds targeted debug logging to sys.IsRunningInContainer() to make container detection decisions observable via the project’s DEBUG-controlled logger namespaces.

Changes:

  • Introduces a package-level debug logger for internal/sys/container.go.
  • Logs container detection flow at function entry, on each positive detection path, and on the “no indicators found” fallback.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

"github.com/github/gh-aw-mcpg/internal/logger"
)

var logSys = logger.New("sys:container")
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logger variable name logSys is not very descriptive in the sys package and deviates from the documented convention to use log<Component> names matching the component (e.g., logLauncher, logValidation). Consider renaming this to something like logContainer (or similar) to make its purpose clear and reduce ambiguity when grepping logs.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants