Skip to content

Commit bdf5316

Browse files
add debug logs for github api requests (#2047)
* add debug logs for github api requests * log ee as well * fetch specific headers only * reduce logging * Update backend/utils/trip_logger.go Co-authored-by: bismuthdev[bot] <177057995+bismuthdev[bot]@users.noreply.github.com> --------- Co-authored-by: bismuthdev[bot] <177057995+bismuthdev[bot]@users.noreply.github.com>
1 parent 60012d0 commit bdf5316

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

backend/utils/github.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,11 @@ func (gh DiggerGithubRealClientProvider) Get(githubAppId int64, installationId i
8383
return nil, nil, fmt.Errorf("error initialising git app token: %v\n", err)
8484
}
8585

86-
ghClient, err := gh.NewClient(&net.Client{Transport: itr})
86+
clientWithLogging := &net.Client{
87+
Transport: &LoggingRoundTripper{Rt: itr},
88+
}
89+
90+
ghClient, err := gh.NewClient(clientWithLogging)
8791
if err != nil {
8892
slog.Error("Failed to create GitHub client", "error", err)
8993
return nil, nil, fmt.Errorf("error creating new client: %v", err)

backend/utils/trip_logger.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package utils
2+
3+
import (
4+
"log/slog"
5+
net "net/http"
6+
)
7+
8+
type LoggingRoundTripper struct {
9+
Rt net.RoundTripper
10+
}
11+
12+
func (lrt *LoggingRoundTripper) RoundTrip(req *net.Request) (*net.Response, error) {
13+
// Log the request
14+
slog.Debug("GitHub API Request",
15+
"method", req.Method,
16+
"url_path", req.URL.Path,
17+
)
18+
19+
resp, err := lrt.Rt.RoundTrip(req)
20+
if err != nil {
21+
slog.Error("GitHub API Request failed", "error", err)
22+
return nil, err
23+
}
24+
25+
slog.Debug("GitHub API Response",
26+
"status", resp.Status,
27+
)
28+
29+
if resp.Header != nil {
30+
slog.Debug("GitHub API Rate Limits",
31+
"X-RateLimit-Limit", resp.Header.Get("X-RateLimit-Limit"),
32+
"X-RateLimit-Remaining", resp.Header.Get("X-RateLimit-Remaining"),
33+
"X-RateLimit-Used", resp.Header.Get("X-RateLimit-Used"),
34+
"X-RateLimit-Resource", resp.Header.Get("X-RateLimit-Resource"),
35+
"X-RateLimit-Reset", resp.Header.Get("X-RateLimit-Reset"),
36+
)
37+
}
38+
39+
return resp, nil
40+
}

ee/backend/providers/github/providers.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,11 @@ func (gh DiggerGithubEEClientProvider) Get(githubAppId int64, installationId int
8080
return nil, nil, fmt.Errorf("error initialising git app token: %v\n", err)
8181
}
8282

83-
ghClient, err := gh.NewClient(&net.Client{Transport: itr})
83+
clientWithLogging := &net.Client{
84+
Transport: &utils.LoggingRoundTripper{Rt: itr},
85+
}
86+
87+
ghClient, err := gh.NewClient(clientWithLogging)
8488
if err != nil {
8589
return nil, nil, fmt.Errorf("could not get digger client: %v", err)
8690
}

0 commit comments

Comments
 (0)