diff --git a/auth/token_generator.go b/auth/token_generator.go index ddf777be..7aa2d564 100644 --- a/auth/token_generator.go +++ b/auth/token_generator.go @@ -172,12 +172,12 @@ type iamSigner struct { func newIAMSigner(ctx context.Context, config *internal.AuthConfig) (*iamSigner, error) { hc, _, err := internal.NewHTTPClient(ctx, config.Opts...) - hc.Opts = []internal.HTTPOption{ - internal.WithHeader("x-goog-api-client", internal.GetMetricsHeader(config.Version)), - } if err != nil { return nil, err } + hc.Opts = []internal.HTTPOption{ + internal.WithHeader("x-goog-api-client", internal.GetMetricsHeader(config.Version)), + } return &iamSigner{ mutex: &sync.Mutex{}, diff --git a/iid/iid.go b/iid/iid.go index 259f3c36..7a3e9b55 100644 --- a/iid/iid.go +++ b/iid/iid.go @@ -116,12 +116,12 @@ func NewClient(ctx context.Context, c *internal.InstanceIDConfig) (*Client, erro } hc, _, err := internal.NewHTTPClient(ctx, c.Opts...) - hc.Opts = []internal.HTTPOption{ - internal.WithHeader("x-goog-api-client", internal.GetMetricsHeader(c.Version)), - } if err != nil { return nil, err } + hc.Opts = []internal.HTTPOption{ + internal.WithHeader("x-goog-api-client", internal.GetMetricsHeader(c.Version)), + } hc.CreateErrFn = createError return &Client{ diff --git a/internal/http_client.go b/internal/http_client.go index 9adffefd..9463f98e 100644 --- a/internal/http_client.go +++ b/internal/http_client.go @@ -444,6 +444,7 @@ func retryNetworkAndHTTPErrors(statusCodes ...int) RetryCondition { } } +// GetMetricsHeader constructs header value for metrics attribution func GetMetricsHeader(sdkVersion string) string { goVersion := strings.TrimPrefix(runtime.Version(), "go") return fmt.Sprintf("gl-go/%s fire-admin/%s", goVersion, sdkVersion)