[log] Add debug logging to DIFC agent module#751
Conversation
- Added internal logger import and declaration following pkg:filename convention - Added debug logging to NewAgentLabels() to track agent creation - Added debug logging to NewAgentLabelsWithTags() with initial tag info - Added debug logging to AddSecrecyTag() before lock acquisition - Added debug logging to AddIntegrityTag() before lock acquisition - Added debug logging to GetOrCreate() for cache hits and race conditions - All logging follows project conventions with no side effects in arguments - Complements existing operational logs without duplication
There was a problem hiding this comment.
Pull request overview
Adds DIFC agent-level debug logging via the repository’s internal logger facility to improve traceability of agent label creation and registry lookup/creation paths.
Changes:
- Introduces a DIFC agent debug logger (
logAgent = logger.New("difc:agent")). - Adds debug
Printfcalls to agent label constructors and tag mutation methods. - Adds debug logging around
AgentRegistry.GetOrCreatecontrol flow (call entry, cache hit, double-check hit).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // GetOrCreate gets an existing agent or creates a new one with default labels | ||
| func (r *AgentRegistry) GetOrCreate(agentID string) *AgentLabels { | ||
| logAgent.Printf("GetOrCreate called for agentID=%s", agentID) | ||
|
|
There was a problem hiding this comment.
Line contains trailing whitespace on an otherwise blank line; please remove it (or run gofmt) to avoid noisy diffs and keep formatting consistent.
| if labels, ok := r.agents[agentID]; ok { | ||
| logAgent.Printf("Agent %s created by another goroutine", agentID) | ||
| return labels |
There was a problem hiding this comment.
This debug log executes while holding r.mu (write lock). When DEBUG is enabled, logger.Printf performs I/O and can noticeably extend the critical section, increasing contention. Consider moving the log outside the locked section (e.g., capture the condition/labels, unlock, then log and return).
Summary
Enhanced
internal/difc/agent.gowith debug logging using the internal logger package, following project conventions from AGENTS.md.Changes
Added internal logger infrastructure:
github.com/github/gh-aw-mcpg/internal/loggervar logAgent = logger.New("difc:agent")following thepkg:filenamenaming conventionAdded debug logging to 5 key functions:
NewAgentLabels()- Logs agent creation with agentIDNewAgentLabelsWithTags()- Logs agent creation with initial secrecy/integrity tagsAddSecrecyTag()- Logs before acquiring lock for secrecy tag additionAddIntegrityTag()- Logs before acquiring lock for integrity tag additionGetOrCreate()- Logs agent lookup/creation flow including:Design Principles
pkg:filenamenaming pattern and logger best practicesTesting
Due to environment constraints, the changes require CI validation:
The code changes are syntactically correct and follow all project conventions. CI will verify:
Debugging Usage
Enable DIFC agent debug logging:
Files Changed
internal/difc/agent.go- 1 file, +13 lines (7 debug logging calls)Related
This PR is part of the ongoing effort to enhance debug logging across the codebase for better troubleshooting and development visibility.