Skip to content

Commit 9831a62

Browse files
committed
auth: add span to FetchToken helpers
Before this, during a call to the docker resolver, we would generate span wrappers for each HTTPRequest correctly, however, as the docker resolver reaches out to the docker authorizer, it could create HTTP requests (for fetching tokens) that would not be wrapped in any span. This can result in rather confusing traces, e.g. something like: remotes.docker.resolver.HTTPRequest HTTP HEAD (fetch index, fails with 401) HTTP GET (fetch token) remotes.docker.resolver.HTTPRequest HTTP HEAD (fetch index) remotes.docker.resolver.HTTPRequest HTTP GET (fetch manifest) By adding a span into the FetchToken, this trace becomes a little easier to consume: remotes.docker.resolver.HTTPRequest HTTP HEAD (fetch index, fails with 401) remotes.docker.resolver.FetchToken HTTP GET (fetch token) remotes.docker.resolver.HTTPRequest HTTP HEAD (fetch index) remotes.docker.resolver.HTTPRequest HTTP GET (fetch manifest) Signed-off-by: Justin Chadwell <me@jedevc.com>
1 parent 536608e commit 9831a62

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

core/remotes/docker/auth/fetch.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"time"
2828

2929
remoteserrors "github.com/containerd/containerd/v2/core/remotes/errors"
30+
"github.com/containerd/containerd/v2/pkg/tracing"
3031
"github.com/containerd/containerd/v2/version"
3132
"github.com/containerd/log"
3233
)
@@ -95,6 +96,10 @@ type OAuthTokenResponse struct {
9596

9697
// FetchTokenWithOAuth fetches a token using a POST request
9798
func FetchTokenWithOAuth(ctx context.Context, client *http.Client, headers http.Header, clientID string, to TokenOptions) (*OAuthTokenResponse, error) {
99+
c := *client
100+
client = &c
101+
tracing.UpdateHTTPClient(client, tracing.Name("remotes.docker.resolver", "FetchTokenWithOAuth"))
102+
98103
form := url.Values{}
99104
if len(to.Scopes) > 0 {
100105
form.Set("scope", strings.Join(to.Scopes, " "))
@@ -161,6 +166,10 @@ type FetchTokenResponse struct {
161166

162167
// FetchToken fetches a token using a GET request
163168
func FetchToken(ctx context.Context, client *http.Client, headers http.Header, to TokenOptions) (*FetchTokenResponse, error) {
169+
c := *client
170+
client = &c
171+
tracing.UpdateHTTPClient(client, tracing.Name("remotes.docker.resolver", "FetchToken"))
172+
164173
req, err := http.NewRequestWithContext(ctx, http.MethodGet, to.Realm, nil)
165174
if err != nil {
166175
return nil, err

0 commit comments

Comments
 (0)