Skip to content

Commit

Permalink
Add client_info support to clients. (#7899)
Browse files Browse the repository at this point in the history
  • Loading branch information
tseaver authored May 8, 2019
1 parent 1925cb2 commit d613b57
Show file tree
Hide file tree
Showing 8 changed files with 176 additions and 239 deletions.
7 changes: 1 addition & 6 deletions trace/google/cloud/trace/_gapic.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,15 @@

"""Wrapper for interacting with the Stackdriver Trace API."""

from google.api_core.gapic_v1 import client_info
from google.api_core.gapic_v1 import method
from google.cloud._helpers import _datetime_to_pb_timestamp
from google.cloud.trace import __version__
from google.cloud.trace_v2.gapic import trace_service_client
from google.cloud.trace_v2.proto import trace_pb2
from google.protobuf.json_format import ParseDict
from google.rpc import status_pb2 as google_dot_rpc_dot_status__pb2
from google.protobuf import wrappers_pb2 as google_dot_protobuf_dot_wrappers__pb2


_CLIENT_INFO = client_info.ClientInfo(client_library_version=__version__)


class _TraceAPI(object):
"""
Wrapper to help mapping trace-related APIs.
Expand Down Expand Up @@ -319,6 +314,6 @@ def make_trace_api(client):
proper configurations.
"""
generated = trace_service_client.TraceServiceClient(
credentials=client._credentials, client_info=_CLIENT_INFO
credentials=client._credentials, client_info=client._client_info
)
return _TraceAPI(generated, client)
15 changes: 13 additions & 2 deletions trace/google/cloud/trace/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@

"""Client for interacting with the Stackdriver Trace API."""

from google.cloud.trace._gapic import make_trace_api
from google.api_core.gapic_v1 import client_info
from google.cloud.client import ClientWithProject
from google.cloud.trace import __version__
from google.cloud.trace._gapic import make_trace_api


_CLIENT_INFO = client_info.ClientInfo(client_library_version=__version__)


class Client(ClientWithProject):
Expand All @@ -29,6 +34,11 @@ class Client(ClientWithProject):
credentials (Optional[:class:`~google.auth.credentials.Credentials`]):
The OAuth2 Credentials to use for this client. If not passed,
falls back to the default inferred from the environment.
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
The client info used to send a user-agent string along with API
requests. If ``None``, then default info will be used. Generally,
you only need to set this if you're developing your own library
or partner tool.
"""

SCOPE = (
Expand All @@ -39,8 +49,9 @@ class Client(ClientWithProject):

_trace_api = None

def __init__(self, project=None, credentials=None):
def __init__(self, project=None, credentials=None, client_info=_CLIENT_INFO):
super(Client, self).__init__(project=project, credentials=credentials)
self._client_info = client_info

@property
def trace_api(self):
Expand Down
2 changes: 1 addition & 1 deletion trace/google/cloud/trace/v1/_gapic.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def make_trace_api(client):
proper configurations.
"""
generated = trace_service_client.TraceServiceClient(
credentials=client._credentials, client_info=_CLIENT_INFO
credentials=client._credentials, client_info=client._client_info
)
return _TraceAPI(generated, client)

Expand Down
18 changes: 14 additions & 4 deletions trace/google/cloud/trace/v1/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@

"""Client for interacting with the Stackdriver Trace API."""

from google.cloud.trace.v1._gapic import make_trace_api
from google.cloud.client import ClientWithProject
from google.api_core.gapic_v1 import client_info
from google.cloud._helpers import _datetime_to_pb_timestamp
from google.cloud.client import ClientWithProject
from google.cloud.trace import __version__
from google.cloud.trace.v1._gapic import make_trace_api


_CLIENT_INFO = client_info.ClientInfo(client_library_version=__version__)


class Client(ClientWithProject):
Expand All @@ -27,11 +32,15 @@ class Client(ClientWithProject):
project (str): Required. The project which the client acts on behalf
of. If not passed, falls back to the default inferred
from the environment.
credentials (Optional[~google.auth.credentials.Credentials]):
The OAuth2 Credentials to use for this client. If not
passed, falls back to the default inferred from the
environment.
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
The client info used to send a user-agent string along with API
requests. If ``None``, then default info will be used. Generally,
you only need to set this if you're developing your own library
or partner tool.
"""

SCOPE = (
Expand All @@ -42,8 +51,9 @@ class Client(ClientWithProject):

_trace_api = None

def __init__(self, project=None, credentials=None):
def __init__(self, project=None, credentials=None, client_info=_CLIENT_INFO):
super(Client, self).__init__(project=project, credentials=credentials)
self._client_info = client_info

@property
def trace_api(self):
Expand Down
Loading

0 comments on commit d613b57

Please sign in to comment.