diff --git a/clients/githubrepo/roundtripper/rate_limit.go b/clients/githubrepo/roundtripper/rate_limit.go index 9730616d1f1..950e8f8aa8b 100644 --- a/clients/githubrepo/roundtripper/rate_limit.go +++ b/clients/githubrepo/roundtripper/rate_limit.go @@ -21,6 +21,7 @@ import ( "time" "go.opencensus.io/stats" + "go.opencensus.io/tag" githubstats "github.com/ossf/scorecard/v4/clients/githubrepo/stats" sce "github.com/ossf/scorecard/v4/errors" @@ -63,6 +64,11 @@ func (gh *rateLimitTransport) RoundTrip(r *http.Request) (*http.Response, error) if err != nil { return resp, nil } + ctx, err := tag.New(r.Context(), tag.Upsert(githubstats.ResourceType, resp.Header.Get("X-RateLimit-Resource"))) + if err != nil { + return nil, fmt.Errorf("error updating context: %w", err) + } + stats.Record(ctx, githubstats.RemainingTokens.M(int64(remaining))) if remaining <= 0 { reset, err := strconv.Atoi(resp.Header.Get("X-RateLimit-Reset")) diff --git a/clients/githubrepo/roundtripper/transport.go b/clients/githubrepo/roundtripper/transport.go index fa606979459..d8c577ed168 100644 --- a/clients/githubrepo/roundtripper/transport.go +++ b/clients/githubrepo/roundtripper/transport.go @@ -17,9 +17,7 @@ package roundtripper import ( "fmt" "net/http" - "strconv" - "go.opencensus.io/stats" "go.opencensus.io/tag" "github.com/ossf/scorecard/v4/clients/githubrepo/roundtripper/tokens" @@ -56,14 +54,5 @@ func (gt *githubTransport) RoundTrip(r *http.Request) (*http.Response, error) { return nil, fmt.Errorf("error in HTTP: %w", err) } - ctx, err = tag.New(r.Context(), tag.Upsert(githubstats.ResourceType, resp.Header.Get("X-RateLimit-Resource"))) - if err != nil { - return nil, fmt.Errorf("error updating context: %w", err) - } - remaining, err := strconv.Atoi(resp.Header.Get("X-RateLimit-Remaining")) - if err == nil { - stats.Record(ctx, githubstats.RemainingTokens.M(int64(remaining))) - } - return resp, nil }