[log] Add debug logging to GenerateRandomAPIKey in auth/apikey.go#4002
[log] Add debug logging to GenerateRandomAPIKey in auth/apikey.go#4002
Conversation
Log function entry, success, and failure for GenerateRandomAPIKey using the existing package-level debug logger (declared in auth/header.go). This provides visibility into API key generation at startup when DEBUG=auth:* is enabled. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds debug-level logging around random API key generation in the internal/auth package to improve startup diagnostics when no API key is configured.
Changes:
- Log entry into
GenerateRandomAPIKey - Log the underlying error when key generation fails
- Log successful completion of key generation (without logging the key)
Show a summary per file
| File | Description |
|---|---|
| internal/auth/apikey.go | Adds debug logs around random API key generation for easier startup troubleshooting. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 1/1 changed files
- Comments generated: 1
| log.Print("Generating random API key") | ||
| key, err := strutil.RandomHex(32) | ||
| if err != nil { | ||
| log.Printf("Random API key generation failed: %v", err) |
There was a problem hiding this comment.
These new debug logs are emitted via the package-level log declared in header.go with namespace auth:header, so API-key generation messages will be tagged as auth:header. This makes log filtering/searching misleading (e.g., you can’t enable just API-key logs) and doesn’t match the behavior being logged. Consider introducing a dedicated logger for this file (e.g., auth:apikey) or renaming the existing logger namespace to something broader and updating call sites accordingly.
See below for a potential fix:
stdlog "log"
"os"
"github.com/github/gh-aw-mcpg/internal/strutil"
)
var apiKeyLog = stdlog.New(os.Stderr, "auth:apikey ", 0)
// GenerateRandomAPIKey generates a cryptographically random API key.
// Per spec §7.3, the gateway SHOULD generate a random API key on startup
// if none is provided. Returns a 32-byte hex-encoded string (64 chars).
func GenerateRandomAPIKey() (string, error) {
apiKeyLog.Print("Generating random API key")
key, err := strutil.RandomHex(32)
if err != nil {
apiKeyLog.Printf("Random API key generation failed: %v", err)
return "", fmt.Errorf("failed to generate random API key: %w", err)
}
apiKeyLog.Print("Random API key generated successfully")
|
@copilot address the review feedback #4002 (review) |
Agent-Logs-Url: https://github.com/github/gh-aw-mcpg/sessions/568a79f5-6ac8-4127-89d4-a791265c20b9 Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Implemented in ce2abc8: Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Summary
Adds 3 debug logging calls to
internal/auth/apikey.gousing the existing package-level logger (log, declared inauth/header.go).Changes
internal/auth/apikey.go— 3 newlog.Print/log.Printfcalls inGenerateRandomAPIKey:"Generating random API key""Random API key generation failed: %v""Random API key generated successfully"Why this file?
GenerateRandomAPIKeyis called at gateway startup (spec §7.3) whenever no API key is configured. Logging this lifecycle event helps developers:strutil.RandomHex(e.g., entropy issues)DEBUG=auth:*outputDesign decisions
var log = logger.New("auth:header")is already declared in theauthpackage. No new logger variable or import is needed inapikey.go.Validation
go build ./...✅go vet ./...✅go test ./internal/auth/...✅ (all tests pass)go test ./...✅ (all unit tests pass; pre-existing integration test failures unrelated to this change)Enabling debug output
DEBUG=auth:* ./awmg --config config.tomlWarning
The following domain was blocked by the firewall during workflow execution:
invalidhostthatdoesnotexist12345.comTo allow these domains, add them to the
network.allowedlist in your workflow frontmatter:See Network Configuration for more information.