Google-cloud-python: Add `client_info` to constructors for manual clients

Created on 30 Apr 2019  路  7Comments  路  Source: googleapis/google-cloud-python

The client_info constructor argument is the standard argument for changing user agent headers in GAPIC clients. Adding a user_agent prefix identifying an app or tool is required for many partners who use Google APIs.

Handwritten clients should provide a similar client_info argument to the client constructor. See how this was done in BigQuery at https://github.com/googleapis/google-cloud-python/pull/7806.

Clients that need client_info:

  • [x] BigQuery (https://github.com/googleapis/google-cloud-python/pull/7806)
  • [x] [Bigtable](https://github.com/googleapis/google-cloud-python/blob/af3df9cc2c520ef48870e124b65849c37966c43e/bigtable/google/cloud/bigtable/client.py#L76) (#7876)
  • [x] [Datastore](https://github.com/googleapis/google-cloud-python/blob/92465cbc4d9c0ba251838e9cd17f61d14b470e04/datastore/google/cloud/datastore/client.py#L165)
  • [x] [DNS](https://github.com/googleapis/google-cloud-python/blob/ff05ac3a8fa58a696584bada6ac89eb0a81e9856/dns/google/cloud/dns/client.py#L24) (#7869)
  • [x] [Error Reporting](https://github.com/googleapis/google-cloud-python/blob/92465cbc4d9c0ba251838e9cd17f61d14b470e04/error_reporting/google/cloud/error_reporting/client.py#L84) (#7903)
  • [x] [Firestore](https://github.com/googleapis/google-cloud-python/blob/894243931e41e1e9e71762d4cabd2dbe7c39b6af/firestore/google/cloud/firestore_v1/client.py#L51) (and Firestore Beta) (#7877, V1 only, see below)
  • [x] [Logging](https://github.com/googleapis/google-cloud-python/blob/aee5ceca1561e7f2c92a71b7be026851c5cb5d41/logging/google/cloud/logging/client.py#L59) (#7874, #7901)
  • [x] Pub/Sub (Publisher, Subscriber) (done via **kwargs)
  • [x] [Resource Manager](https://github.com/googleapis/google-cloud-python/blob/ff05ac3a8fa58a696584bada6ac89eb0a81e9856/resource_manager/google/cloud/resource_manager/client.py#L26) (#7870)
  • [x] [Runtime Config](https://github.com/googleapis/google-cloud-python/blob/9e804dfb2fa1ca4a29e861d88600f924906776d6/runtimeconfig/google/cloud/runtimeconfig/client.py#L24) (#7871)
  • [x] [Spanner](https://github.com/googleapis/google-cloud-python/blob/ff05ac3a8fa58a696584bada6ac89eb0a81e9856/spanner/google/cloud/spanner_v1/client.py#L78) - Note: Spanner has a user_agent argument already, but it's currently a no-op. Should mark that as deprecated. (#7878)
  • [x] [Storage](https://github.com/googleapis/google-cloud-python/blob/ff05ac3a8fa58a696584bada6ac89eb0a81e9856/storage/google/cloud/storage/client.py#L32) (#7872)
  • [x] [Trace](https://github.com/googleapis/google-cloud-python/blob/c0abaa4d6860bcdd621d00d0e0bad94237b964b5/trace/google/cloud/trace/client.py#L21) and Trace V1 (#7899)
  • [x] [Translate](https://github.com/googleapis/google-cloud-python/blob/9e804dfb2fa1ca4a29e861d88600f924906776d6/translate/google/cloud/translate_v2/client.py#L35) (#7873, no GRPC version needed, because v3beta1 is pure-autogen)

I've heard requests for this feature in the Storage client, so I'd prioritize that one above the others, but we do need this feature across all clients.

feature request datastore storage bigquery dns pubsub bigtable cloudresourcemanager logging translation runtimeconfig spanner clouderrorreporting cloudtrace firestore

All 7 comments

My current plan:

  • Hoist @tswast's work from #7806 up into the google.cloud._http.JSONConnection base class. (#7849)
  • Deprecate the USER_AGENT and _EXTRA_HEADERS class-scope constants in that class, in favor of new instance properties, user_agent / extra_headers. Replace the deprecated class-scope names with properties which emit warnings when assigned. (#7849)
  • Document the client_info parameter in all classes which derive from JSONConnection.
  • Add client_info to the constructor of those clients which use connections based on JSONConnection, and pass it through to the connections (storage, dns, logging, resource_manager, runtimeconnection, translate).
  • For clients which do not use JSONConnection, add client_info to their constructors and forward it to their GAPIC clients.

@tswast One thing I've noticed while deprecating the _EXTRA_HEADERS variable: you bend over backwards to allow self._EXTRA_HEADERS["foo"] = "bar". I think I'd rather avoid supporting that, and instead just allow assignment to it. WDYT?

I think I'd rather avoid supporting that, and instead just allow assignment to it. WDYT?

Seems reasonable, since we're making a new property name now. I bent over backwards because we had some tests that did key assignment and I wanted to maintain compatibility.

@tswast I just realized that since we've hoisted the logic for adding the X-Goog-API-Client header into the base class, we can avoid jamming it into the extra_headers return value, which makes allowing assignment into it simple.

@tswast I think we should leave this feature out of the firestore_v1beta1 client object: the Firestore team really doesn't want to encourage new users for that version of the API.

Thanks @tseaver ! The REST clients LGTM. A few questions on the gapic clients.

馃帀 Thanks! 馃帀

Are we following-up with a bunch of releases next (or at least for api_core)?

Was this page helpful?
0 / 5 - 0 ratings