Skip to content

Commit a774683

Browse files
authored
[log] Add debug logging to difc/sink_server_ids (#2034)
## Summary Adds a debug logger (`logSink`) to `internal/difc/sink_server_ids.go` using the project's standard `logger.New("difc:sink_server_ids")` pattern. This file configures which backend server IDs receive DIFC tag snapshot enrichment in RPC JSONL logs, and previously had no debug visibility. ## Changes **File modified:** `internal/difc/sink_server_ids.go` - Added `logger` import and `var logSink = logger.New("difc:sink_server_ids")` declaration - **`SetSinkServerIDs`**: logs input count on entry, logs when config is cleared, logs skipped duplicate IDs, logs final normalized IDs and count after sorting - **`IsSinkServerID`**: logs when a match is found (called frequently, so only logs on positive match to minimize noise) ## Logging calls added (5 total) | Location | Message | Purpose | |---|---|---| | `SetSinkServerIDs` entry | `Setting sink server IDs: input_count=N` | Trace configuration calls | | `SetSinkServerIDs` empty case | `No sink server IDs provided, clearing configuration` | Visible config reset | | `SetSinkServerIDs` loop | `Skipping duplicate sink server ID: %s` | Debug dedup logic | | `SetSinkServerIDs` end | `Sink server IDs configured: count=N, ids=[...]` | Final state confirmation | | `IsSinkServerID` match | `Sink server ID match: serverID=%s` | Trace positive lookups | ## Logger naming convention Follows `pkg:filename` convention: `"difc:sink_server_ids"` for `internal/difc/sink_server_ids.go`. ## Testing Enable with `DEBUG=difc:* ./awmg --config config.toml` to see all difc debug logs including the new sink server ID logs. > Generated by [Go Logger Enhancement](https://github.com/github/gh-aw-mcpg/actions/runs/23152584774) · [◷](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, id: 23152584774, workflow_id: go-logger, run: https://github.com/github/gh-aw-mcpg/actions/runs/23152584774 --> <!-- gh-aw-workflow-id: go-logger -->
2 parents dd66b23 + ffabdf4 commit a774683

1 file changed

Lines changed: 33 additions & 4 deletions

File tree

internal/difc/sink_server_ids.go

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@ import (
44
"sort"
55
"strings"
66
"sync"
7+
8+
"github.com/github/gh-aw-mcpg/internal/logger"
79
)
810

11+
var logSink = logger.New("difc:sink_server_ids")
12+
913
var (
1014
sinkServerIDsMu sync.RWMutex
1115
sinkServerIDs = []string{}
@@ -14,11 +18,20 @@ var (
1418
// SetSinkServerIDs configures backend server IDs that should receive DIFC tag snapshot
1519
// enrichment in RPC JSONL logs.
1620
func SetSinkServerIDs(serverIDs []string) {
21+
logSink.Printf("Setting sink server IDs: input_count=%d", len(serverIDs))
22+
23+
var (
24+
normalizedOut []string
25+
duplicateIDs []string
26+
)
27+
1728
sinkServerIDsMu.Lock()
18-
defer sinkServerIDsMu.Unlock()
1929

2030
if len(serverIDs) == 0 {
2131
sinkServerIDs = nil
32+
sinkServerIDsMu.Unlock()
33+
34+
logSink.Print("No sink server IDs provided, clearing configuration")
2235
return
2336
}
2437

@@ -30,6 +43,7 @@ func SetSinkServerIDs(serverIDs []string) {
3043
continue
3144
}
3245
if _, exists := unique[trimmed]; exists {
46+
duplicateIDs = append(duplicateIDs, trimmed)
3347
continue
3448
}
3549
unique[trimmed] = struct{}{}
@@ -38,17 +52,32 @@ func SetSinkServerIDs(serverIDs []string) {
3852

3953
sort.Strings(normalized)
4054
sinkServerIDs = normalized
55+
normalizedOut = normalized
56+
57+
sinkServerIDsMu.Unlock()
58+
59+
for _, id := range duplicateIDs {
60+
logSink.Printf("Skipping duplicate sink server ID: %s", id)
61+
}
62+
63+
logSink.Printf("Sink server IDs configured: count=%d, ids=%v", len(normalizedOut), normalizedOut)
4164
}
4265

4366
// IsSinkServerID reports whether serverID is in the configured set of DIFC sink server IDs.
4467
func IsSinkServerID(serverID string) bool {
4568
sinkServerIDsMu.RLock()
46-
defer sinkServerIDsMu.RUnlock()
47-
69+
matched := false
4870
for _, sinkServerID := range sinkServerIDs {
4971
if serverID == sinkServerID {
50-
return true
72+
matched = true
73+
break
5174
}
5275
}
76+
sinkServerIDsMu.RUnlock()
77+
78+
if matched {
79+
logSink.Printf("Sink server ID match: serverID=%s", serverID)
80+
return true
81+
}
5382
return false
5483
}

0 commit comments

Comments
 (0)