[log] log: add debug logging to difc/agent.go#1461
Conversation
Add logAgent debug logging to six functions in AgentLabels and AgentRegistry that previously lacked debug tracing: - DropIntegrityTag: log tag being dropped before deletion - AccumulateFromRead: log resource description at entry - NewAgentRegistry: log registry creation - Get: log lookup result (agentID and found status) - Register: log explicit label registration at entry - Remove: log agent removal at entry All new log calls reuse the existing logAgent variable and follow the pkg:filename naming convention. Log arguments are simple field accesses with no side effects. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR adds 6 logAgent debug logging calls to internal/difc/agent.go, covering functions that previously lacked tracing via the DEBUG=difc:* mechanism. It reuses the existing var logAgent = logger.New("difc:agent") logger and adds entry-point logs to DropIntegrityTag, AccumulateFromRead, NewAgentRegistry, Get, Register, and Remove.
Changes:
- Adds debug log before lock acquisition in
DropIntegrityTagandAccumulateFromRead - Adds a debug log at the start of
NewAgentRegistry - Adds debug logs to
Get,Register, andRemoveregistry methods
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| defer r.mu.RUnlock() | ||
| labels, ok := r.agents[agentID] |
There was a problem hiding this comment.
The log statement in Get is placed after the map read and before return, meaning it runs while r.mu.RLock() is still held (the deferred RUnlock hasn't fired yet). Every other logging call in this file that involves locks — AddSecrecyTag, AddIntegrityTag, DropIntegrityTag, AccumulateFromRead, Register, Remove — logs before acquiring the lock. For consistency and to minimize the time the read lock is held, the log call should be moved to before r.mu.RLock(). The values agentID, and ok can still be logged if ok is captured before the early return: log before locking (at entry), report found/not-found after reading but before logging — or simply move the log before the lock like all other functions do.
| defer r.mu.RUnlock() | |
| labels, ok := r.agents[agentID] | |
| labels, ok := r.agents[agentID] | |
| r.mu.RUnlock() |
|
|
||
| // NewAgentRegistry creates a new agent registry | ||
| func NewAgentRegistry() *AgentRegistry { | ||
| logAgent.Print("Creating new agent registry") |
There was a problem hiding this comment.
NewAgentRegistry now has a log call added, but its sibling constructor NewAgentRegistryWithDefaults (line 137, just below) does not. In the test suite, NewAgentRegistryWithDefaults is used exclusively, so debugging registry creation via DEBUG=difc:* will produce no output for the most commonly used code path. For consistent observability, a matching log call should be added to NewAgentRegistryWithDefaults as well.
Summary
Adds 6 meaningful
logAgentdebug logging calls tointernal/difc/agent.go, covering functions that previously lacked debug tracing.Changes
File modified:
internal/difc/agent.goReuses the existing
var logAgent = logger.New("difc:agent")logger (no new imports needed) and adds logging to:DropIntegrityTagAccumulateFromReadNewAgentRegistryGetRegisterRemoveQuality checklist
logAgentlogger reused (no duplicate declaration)pkg:filenameconvention (difc:agent)Debugging value
These additions enable developers to trace DIFC label lifecycle with
DEBUG=difc:*: