Skip to content

Commit 997ca69

Browse files
authored
[log] Add debug logging to proxy upstream forwarding (#14309)
Adds 5 debug log calls to `internal/proxy/proxy.go`, reusing the existing `logProxy` logger: - `upstreamHost`: scheme-less parse retry and raw host fallback - `forwardToGitHub`: GraphQL URL rewrite (GHES or not), request creation failure, artifact zip no-redirect path The log arguments have no side effects. They don't log paths, URLs or credentials, so enclave and delegation modes stay safe. Validation: `go vet` and `go test ./internal/proxy` pass, and `go build` succeeds. > Generated by [Go Logger Enhancement](https://github.com/github/gh-aw-mcpg/actions/runs/37077512907) · copilot · auto · 62.4 AIC · ⊞ 12.8K · [◷](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, model: auto, id: 37077512907, workflow_id: go-logger, run: https://github.com/github/gh-aw-mcpg/actions/runs/37077512907 --> <!-- gh-aw-workflow-id: go-logger --> <!-- gh-aw-workflow-call-id: github/gh-aw-mcpg/go-logger -->
2 parents 0205ffe + b085fa6 commit 997ca69

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

‎internal/proxy/proxy.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,12 +457,14 @@ func (s *Server) upstreamHost() string {
457457
}
458458

459459
// Handle scheme-less config values like "api.github.com" or "api.github.com/api/v3".
460+
logProxy.Print("upstreamHost: githubAPIURL has no host, retrying parse as scheme-less value")
460461
u, err = url.Parse("https://" + strings.TrimLeft(s.githubAPIURL, "/"))
461462
if err == nil && u.Host != "" {
462463
return u.Hostname()
463464
}
464465

465466
host, _, _ := strings.Cut(strings.TrimLeft(s.githubAPIURL, "/"), "/")
467+
logProxy.Print("upstreamHost: falling back to raw host segment")
466468
return host
467469
}
468470

@@ -483,6 +485,7 @@ func (s *Server) forwardToGitHub(ctx context.Context, method, path string, body
483485
graphqlURL = s.githubAPIURL + "/graphql"
484486
}
485487
url = graphqlURL
488+
logProxy.Printf("forwardToGitHub: rewrote GraphQL upstream URL: ghes=%v", strings.HasSuffix(s.githubAPIURL, "/api/v3"))
486489
if hasQuery {
487490
url += "?" + query
488491
}
@@ -497,6 +500,7 @@ func (s *Server) forwardToGitHub(ctx context.Context, method, path string, body
497500

498501
req, err := http.NewRequestWithContext(ctx, method, url, body)
499502
if err != nil {
503+
logProxy.Printf("forwardToGitHub: failed to create upstream request: method=%s, err=%s", method, sanitize.RedactErrorForLog(err))
500504
return nil, fmt.Errorf("failed to create upstream request: %w", err)
501505
}
502506

@@ -514,6 +518,7 @@ func (s *Server) forwardToGitHub(ctx context.Context, method, path string, body
514518
req.Header.Set("Content-Type", contentType)
515519
}
516520
if method == http.MethodGet && artifactZipDownloadPathPattern.MatchString(pathOnly) {
521+
logProxy.Print("forwardToGitHub: artifact zip download, not following redirects")
517522
return doWithoutFollowingRedirects(s.httpClient, req)
518523
}
519524
return s.httpClient.Do(req)

0 commit comments

Comments
 (0)