@@ -1547,11 +1547,20 @@ func (c *Config) LoadAndValidate(ctx context.Context) error {
15471547 }
15481548
15491549 c .TokenSource = tokenSource
1550-
15511550 cleanCtx := context .WithValue (ctx , oauth2 .HTTPClient , cleanhttp .DefaultClient ())
1551+ clientOptions := []option.ClientOption {option .WithTokenSource (tokenSource )}
1552+
1553+ // The client libraries allow setting the GOOGLE_CLOUD_QUOTA_PROJECT environment variable
1554+ // directly, which unintentionally takes precedence over provider settings. Ensure that
1555+ // provider settings take precedence by applying to the client library's client directly
1556+ // b/360405077#comment8 - go/tpg-issue/17882
1557+ if c .UserProjectOverride && c .BillingProject != "" {
1558+ quotaProject := c .BillingProject
1559+ clientOptions = append (clientOptions , option .WithQuotaProject (quotaProject ))
1560+ }
15521561
15531562 // 1. MTLS TRANSPORT/CLIENT - sets up proper auth headers
1554- client , _ , err := transport .NewHTTPClient (cleanCtx , option . WithTokenSource ( tokenSource ) )
1563+ client , _ , err := transport .NewHTTPClient (cleanCtx , clientOptions ... )
15551564 if err != nil {
15561565 return err
15571566 }
@@ -1580,6 +1589,10 @@ func (c *Config) LoadAndValidate(ctx context.Context) error {
15801589
15811590 // Ensure $userProject is set for all HTTP requests using the client if specified by the provider config
15821591 // See https://cloud.google.com/apis/docs/system-parameters
1592+ // option.WithQuotaProject automatically sets the quota project in the client.
1593+ // However, this setting won't appear in our request logs since our logging
1594+ // transport sits above the Google client's internal transport. To ensure
1595+ // visibility in debug logging, we explicitly set the quota project here as well.
15831596 if c .UserProjectOverride && c .BillingProject != "" {
15841597 headerTransport .Set ("X-Goog-User-Project" , c .BillingProject )
15851598 }
0 commit comments