diff --git a/gapic/schema/metadata.py b/gapic/schema/metadata.py index dc9389e8f5..480cde40cd 100644 --- a/gapic/schema/metadata.py +++ b/gapic/schema/metadata.py @@ -173,6 +173,11 @@ def proto_package(self) -> str: """Return the proto package for this type.""" return '.'.join(self.package) + @property + def proto_package_versioned(self) -> str: + """Return the versioned proto package for this type.""" + return ".".join(self.convert_to_versioned_package()) + def convert_to_versioned_package(self) -> Tuple[str, ...]: # We need to change the import statement to use an # underscore between the module and the version. For example, diff --git a/gapic/templates/%namespace/%name_%version/%sub/services/%service/async_client.py.j2 b/gapic/templates/%namespace/%name_%version/%sub/services/%service/async_client.py.j2 index 9622866d87..aaf8b02acf 100644 --- a/gapic/templates/%namespace/%name_%version/%sub/services/%service/async_client.py.j2 +++ b/gapic/templates/%namespace/%name_%version/%sub/services/%service/async_client.py.j2 @@ -4,6 +4,7 @@ {% import "%namespace/%name_%version/%sub/services/%service/_client_macros.j2" as macros %} {% import "%namespace/%name_%version/%sub/services/%service/_shared_macros.j2" as shared_macros %} +import logging as std_logging from collections import OrderedDict import re from typing import Dict, Callable, Mapping, MutableMapping, MutableSequence, Optional, {% if service.any_server_streaming %}AsyncIterable, Awaitable, {% endif %}{% if service.any_client_streaming %}AsyncIterator, {% endif %}Sequence, Tuple, Type, Union @@ -52,6 +53,13 @@ from .transports.base import {{ service.name }}Transport, DEFAULT_CLIENT_INFO from .transports.grpc_asyncio import {{ service.grpc_asyncio_transport_name }} from .client import {{ service.client_name }} +try: # pragma: NO COVER + from google.api_core import client_logging # type: ignore + CLIENT_LOGGING_SUPPORTED = True +except ImportError: + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) {# TODO(yon-mg): handle rest transport async client interaction #} class {{ service.async_client_name }}: @@ -243,6 +251,17 @@ class {{ service.async_client_name }}: ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(std_logging.DEBUG): # pragma: NO COVER + _LOGGER.debug( + "Created client `{{ service.meta.address.proto_package_versioned }}.{{ service.async_client_name }}`.", + extra = { + "serviceName": "{{ service.meta.address.proto }}", + "universeDomain": getattr(self._client._transport._credentials, "universe_domain", ""), + "credentialType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}", + "credentialInfo": getattr(self.transport._credentials, "get_cred_info", lambda: None)(), + }, + ) + {% for method in service.methods.values() %} {% with method_name = method.safe_name|snake_case + "_unary" if method.operation_service else method.safe_name|snake_case %} {%+ if not method.server_streaming %}async {% endif %}def {{ method_name }}(self, diff --git a/gapic/templates/%namespace/%name_%version/%sub/services/%service/client.py.j2 b/gapic/templates/%namespace/%name_%version/%sub/services/%service/client.py.j2 index 4d78dc0c75..0bcc2406cc 100644 --- a/gapic/templates/%namespace/%name_%version/%sub/services/%service/client.py.j2 +++ b/gapic/templates/%namespace/%name_%version/%sub/services/%service/client.py.j2 @@ -10,6 +10,7 @@ from collections import OrderedDict {% if service.any_extended_operations_methods %} import functools {% endif %} +import logging as std_logging import os import re from typing import Dict, Callable, Mapping, MutableMapping, MutableSequence, Optional, {% if service.any_server_streaming %}Iterable, {% endif %}{% if service.any_client_streaming %}Iterator, {% endif %}Sequence, Tuple, Type, Union, cast @@ -39,6 +40,14 @@ try: except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: # pragma: NO COVER + from google.api_core import client_logging # type: ignore + CLIENT_LOGGING_SUPPORTED = True +except ImportError: + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + {% filter sort_lines %} {% for method in service.methods.values() %} {% for ref_type in method.flat_ref_types %} @@ -510,6 +519,10 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): # Initialize the universe domain validation. self._is_universe_domain_valid = False + if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER + # Setup logging. + client_logging.initialize_logging() + api_key_value = getattr(self._client_options, "api_key", None) if api_key_value and credentials: raise ValueError("client_options.api_key and credentials are mutually exclusive") @@ -596,6 +609,18 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): always_use_jwt_access=True, api_audience=self._client_options.api_audience, ) + + if "async" not in str(self._transport): + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(std_logging.DEBUG): # pragma: NO COVER + _LOGGER.debug( + "Created client `{{ service.meta.address.proto_package_versioned }}.{{ service.client_name }}`.", + extra = { + "serviceName": "{{ service.meta.address.proto }}", + "universeDomain": getattr(self._transport._credentials, "universe_domain", ""), + "credentialType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}", + "credentialInfo": getattr(self.transport._credentials, "get_cred_info", lambda: None)(), + }, + ) {% for method in service.methods.values() %} diff --git a/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/async_client.py b/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/async_client.py index 9effc7f1f1..c911b2dd52 100755 --- a/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/async_client.py +++ b/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/async_client.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import logging as std_logging from collections import OrderedDict import re from typing import Dict, Callable, Mapping, MutableMapping, MutableSequence, Optional, Sequence, Tuple, Type, Union @@ -46,6 +47,13 @@ from .transports.grpc_asyncio import AssetServiceGrpcAsyncIOTransport from .client import AssetServiceClient +try: # pragma: NO COVER + from google.api_core import client_logging # type: ignore + CLIENT_LOGGING_SUPPORTED = True +except ImportError: + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) class AssetServiceAsyncClient: """Asset service definition.""" @@ -247,6 +255,17 @@ def __init__(self, *, ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(std_logging.DEBUG): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.asset_v1.AssetServiceAsyncClient`.", + extra = { + "serviceName": "google.cloud.asset.v1.AssetService", + "universeDomain": getattr(self._client._transport._credentials, "universe_domain", ""), + "credentialType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}", + "credentialInfo": getattr(self.transport._credentials, "get_cred_info", lambda: None)(), + }, + ) + async def export_assets(self, request: Optional[Union[asset_service.ExportAssetsRequest, dict]] = None, *, diff --git a/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/client.py b/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/client.py index ffbc99c45d..779298b9c6 100755 --- a/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/client.py +++ b/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import os import re from typing import Dict, Callable, Mapping, MutableMapping, MutableSequence, Optional, Sequence, Tuple, Type, Union, cast @@ -36,6 +37,14 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: # pragma: NO COVER + from google.api_core import client_logging # type: ignore + CLIENT_LOGGING_SUPPORTED = True +except ImportError: + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.asset_v1.services.asset_service import pagers @@ -566,6 +575,10 @@ def __init__(self, *, # Initialize the universe domain validation. self._is_universe_domain_valid = False + if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER + # Setup logging. + client_logging.initialize_logging() + api_key_value = getattr(self._client_options, "api_key", None) if api_key_value and credentials: raise ValueError("client_options.api_key and credentials are mutually exclusive") @@ -618,6 +631,18 @@ def __init__(self, *, api_audience=self._client_options.api_audience, ) + if "async" not in str(self._transport): + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(std_logging.DEBUG): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.asset_v1.AssetServiceClient`.", + extra = { + "serviceName": "google.cloud.asset.v1.AssetService", + "universeDomain": getattr(self._transport._credentials, "universe_domain", ""), + "credentialType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}", + "credentialInfo": getattr(self.transport._credentials, "get_cred_info", lambda: None)(), + }, + ) + def export_assets(self, request: Optional[Union[asset_service.ExportAssetsRequest, dict]] = None, *, diff --git a/tests/integration/goldens/credentials/google/iam/credentials_v1/services/iam_credentials/async_client.py b/tests/integration/goldens/credentials/google/iam/credentials_v1/services/iam_credentials/async_client.py index ca93c43e38..4dc6b9db32 100755 --- a/tests/integration/goldens/credentials/google/iam/credentials_v1/services/iam_credentials/async_client.py +++ b/tests/integration/goldens/credentials/google/iam/credentials_v1/services/iam_credentials/async_client.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import logging as std_logging from collections import OrderedDict import re from typing import Dict, Callable, Mapping, MutableMapping, MutableSequence, Optional, Sequence, Tuple, Type, Union @@ -39,6 +40,13 @@ from .transports.grpc_asyncio import IAMCredentialsGrpcAsyncIOTransport from .client import IAMCredentialsClient +try: # pragma: NO COVER + from google.api_core import client_logging # type: ignore + CLIENT_LOGGING_SUPPORTED = True +except ImportError: + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) class IAMCredentialsAsyncClient: """A service account is a special type of Google account that @@ -238,6 +246,17 @@ def __init__(self, *, ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(std_logging.DEBUG): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.iam.credentials_v1.IAMCredentialsAsyncClient`.", + extra = { + "serviceName": "google.iam.credentials.v1.IAMCredentials", + "universeDomain": getattr(self._client._transport._credentials, "universe_domain", ""), + "credentialType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}", + "credentialInfo": getattr(self.transport._credentials, "get_cred_info", lambda: None)(), + }, + ) + async def generate_access_token(self, request: Optional[Union[common.GenerateAccessTokenRequest, dict]] = None, *, diff --git a/tests/integration/goldens/credentials/google/iam/credentials_v1/services/iam_credentials/client.py b/tests/integration/goldens/credentials/google/iam/credentials_v1/services/iam_credentials/client.py index c8adeac9aa..2d21452f95 100755 --- a/tests/integration/goldens/credentials/google/iam/credentials_v1/services/iam_credentials/client.py +++ b/tests/integration/goldens/credentials/google/iam/credentials_v1/services/iam_credentials/client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import os import re from typing import Dict, Callable, Mapping, MutableMapping, MutableSequence, Optional, Sequence, Tuple, Type, Union, cast @@ -36,6 +37,14 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: # pragma: NO COVER + from google.api_core import client_logging # type: ignore + CLIENT_LOGGING_SUPPORTED = True +except ImportError: + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + from google.iam.credentials_v1.types import common from google.protobuf import duration_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore @@ -503,6 +512,10 @@ def __init__(self, *, # Initialize the universe domain validation. self._is_universe_domain_valid = False + if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER + # Setup logging. + client_logging.initialize_logging() + api_key_value = getattr(self._client_options, "api_key", None) if api_key_value and credentials: raise ValueError("client_options.api_key and credentials are mutually exclusive") @@ -555,6 +568,18 @@ def __init__(self, *, api_audience=self._client_options.api_audience, ) + if "async" not in str(self._transport): + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(std_logging.DEBUG): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.iam.credentials_v1.IAMCredentialsClient`.", + extra = { + "serviceName": "google.iam.credentials.v1.IAMCredentials", + "universeDomain": getattr(self._transport._credentials, "universe_domain", ""), + "credentialType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}", + "credentialInfo": getattr(self.transport._credentials, "get_cred_info", lambda: None)(), + }, + ) + def generate_access_token(self, request: Optional[Union[common.GenerateAccessTokenRequest, dict]] = None, *, diff --git a/tests/integration/goldens/eventarc/google/cloud/eventarc_v1/services/eventarc/async_client.py b/tests/integration/goldens/eventarc/google/cloud/eventarc_v1/services/eventarc/async_client.py index 38daa4f1c6..d3c86f00e4 100755 --- a/tests/integration/goldens/eventarc/google/cloud/eventarc_v1/services/eventarc/async_client.py +++ b/tests/integration/goldens/eventarc/google/cloud/eventarc_v1/services/eventarc/async_client.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import logging as std_logging from collections import OrderedDict import re from typing import Dict, Callable, Mapping, MutableMapping, MutableSequence, Optional, Sequence, Tuple, Type, Union @@ -55,6 +56,13 @@ from .transports.grpc_asyncio import EventarcGrpcAsyncIOTransport from .client import EventarcClient +try: # pragma: NO COVER + from google.api_core import client_logging # type: ignore + CLIENT_LOGGING_SUPPORTED = True +except ImportError: + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) class EventarcAsyncClient: """Eventarc allows users to subscribe to various events that are @@ -265,6 +273,17 @@ def __init__(self, *, ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(std_logging.DEBUG): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.eventarc_v1.EventarcAsyncClient`.", + extra = { + "serviceName": "google.cloud.eventarc.v1.Eventarc", + "universeDomain": getattr(self._client._transport._credentials, "universe_domain", ""), + "credentialType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}", + "credentialInfo": getattr(self.transport._credentials, "get_cred_info", lambda: None)(), + }, + ) + async def get_trigger(self, request: Optional[Union[eventarc.GetTriggerRequest, dict]] = None, *, diff --git a/tests/integration/goldens/eventarc/google/cloud/eventarc_v1/services/eventarc/client.py b/tests/integration/goldens/eventarc/google/cloud/eventarc_v1/services/eventarc/client.py index a6f0082d35..445c03ea58 100755 --- a/tests/integration/goldens/eventarc/google/cloud/eventarc_v1/services/eventarc/client.py +++ b/tests/integration/goldens/eventarc/google/cloud/eventarc_v1/services/eventarc/client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import os import re from typing import Dict, Callable, Mapping, MutableMapping, MutableSequence, Optional, Sequence, Tuple, Type, Union, cast @@ -36,6 +37,14 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: # pragma: NO COVER + from google.api_core import client_logging # type: ignore + CLIENT_LOGGING_SUPPORTED = True +except ImportError: + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.eventarc_v1.services.eventarc import pagers @@ -611,6 +620,10 @@ def __init__(self, *, # Initialize the universe domain validation. self._is_universe_domain_valid = False + if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER + # Setup logging. + client_logging.initialize_logging() + api_key_value = getattr(self._client_options, "api_key", None) if api_key_value and credentials: raise ValueError("client_options.api_key and credentials are mutually exclusive") @@ -663,6 +676,18 @@ def __init__(self, *, api_audience=self._client_options.api_audience, ) + if "async" not in str(self._transport): + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(std_logging.DEBUG): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.eventarc_v1.EventarcClient`.", + extra = { + "serviceName": "google.cloud.eventarc.v1.Eventarc", + "universeDomain": getattr(self._transport._credentials, "universe_domain", ""), + "credentialType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}", + "credentialInfo": getattr(self.transport._credentials, "get_cred_info", lambda: None)(), + }, + ) + def get_trigger(self, request: Optional[Union[eventarc.GetTriggerRequest, dict]] = None, *, diff --git a/tests/integration/goldens/logging/google/cloud/logging_v2/services/config_service_v2/async_client.py b/tests/integration/goldens/logging/google/cloud/logging_v2/services/config_service_v2/async_client.py index d053be1613..e0f9de6563 100755 --- a/tests/integration/goldens/logging/google/cloud/logging_v2/services/config_service_v2/async_client.py +++ b/tests/integration/goldens/logging/google/cloud/logging_v2/services/config_service_v2/async_client.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import logging as std_logging from collections import OrderedDict import re from typing import Dict, Callable, Mapping, MutableMapping, MutableSequence, Optional, Sequence, Tuple, Type, Union @@ -44,6 +45,13 @@ from .transports.grpc_asyncio import ConfigServiceV2GrpcAsyncIOTransport from .client import ConfigServiceV2Client +try: # pragma: NO COVER + from google.api_core import client_logging # type: ignore + CLIENT_LOGGING_SUPPORTED = True +except ImportError: + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) class ConfigServiceV2AsyncClient: """Service for configuring sinks used to route log entries.""" @@ -242,6 +250,17 @@ def __init__(self, *, ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(std_logging.DEBUG): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.logging_v2.ConfigServiceV2AsyncClient`.", + extra = { + "serviceName": "google.logging.v2.ConfigServiceV2", + "universeDomain": getattr(self._client._transport._credentials, "universe_domain", ""), + "credentialType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}", + "credentialInfo": getattr(self.transport._credentials, "get_cred_info", lambda: None)(), + }, + ) + async def list_buckets(self, request: Optional[Union[logging_config.ListBucketsRequest, dict]] = None, *, diff --git a/tests/integration/goldens/logging/google/cloud/logging_v2/services/config_service_v2/client.py b/tests/integration/goldens/logging/google/cloud/logging_v2/services/config_service_v2/client.py index f6d5e698b0..1d7cabde8f 100755 --- a/tests/integration/goldens/logging/google/cloud/logging_v2/services/config_service_v2/client.py +++ b/tests/integration/goldens/logging/google/cloud/logging_v2/services/config_service_v2/client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import os import re from typing import Dict, Callable, Mapping, MutableMapping, MutableSequence, Optional, Sequence, Tuple, Type, Union, cast @@ -36,6 +37,14 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: # pragma: NO COVER + from google.api_core import client_logging # type: ignore + CLIENT_LOGGING_SUPPORTED = True +except ImportError: + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.logging_v2.services.config_service_v2 import pagers @@ -559,6 +568,10 @@ def __init__(self, *, # Initialize the universe domain validation. self._is_universe_domain_valid = False + if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER + # Setup logging. + client_logging.initialize_logging() + api_key_value = getattr(self._client_options, "api_key", None) if api_key_value and credentials: raise ValueError("client_options.api_key and credentials are mutually exclusive") @@ -611,6 +624,18 @@ def __init__(self, *, api_audience=self._client_options.api_audience, ) + if "async" not in str(self._transport): + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(std_logging.DEBUG): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.logging_v2.ConfigServiceV2Client`.", + extra = { + "serviceName": "google.logging.v2.ConfigServiceV2", + "universeDomain": getattr(self._transport._credentials, "universe_domain", ""), + "credentialType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}", + "credentialInfo": getattr(self.transport._credentials, "get_cred_info", lambda: None)(), + }, + ) + def list_buckets(self, request: Optional[Union[logging_config.ListBucketsRequest, dict]] = None, *, diff --git a/tests/integration/goldens/logging/google/cloud/logging_v2/services/logging_service_v2/async_client.py b/tests/integration/goldens/logging/google/cloud/logging_v2/services/logging_service_v2/async_client.py index a07c53afaa..a74f91a912 100755 --- a/tests/integration/goldens/logging/google/cloud/logging_v2/services/logging_service_v2/async_client.py +++ b/tests/integration/goldens/logging/google/cloud/logging_v2/services/logging_service_v2/async_client.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import logging as std_logging from collections import OrderedDict import re from typing import Dict, Callable, Mapping, MutableMapping, MutableSequence, Optional, AsyncIterable, Awaitable, AsyncIterator, Sequence, Tuple, Type, Union @@ -41,6 +42,13 @@ from .transports.grpc_asyncio import LoggingServiceV2GrpcAsyncIOTransport from .client import LoggingServiceV2Client +try: # pragma: NO COVER + from google.api_core import client_logging # type: ignore + CLIENT_LOGGING_SUPPORTED = True +except ImportError: + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) class LoggingServiceV2AsyncClient: """Service for ingesting and querying logs.""" @@ -227,6 +235,17 @@ def __init__(self, *, ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(std_logging.DEBUG): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.logging_v2.LoggingServiceV2AsyncClient`.", + extra = { + "serviceName": "google.logging.v2.LoggingServiceV2", + "universeDomain": getattr(self._client._transport._credentials, "universe_domain", ""), + "credentialType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}", + "credentialInfo": getattr(self.transport._credentials, "get_cred_info", lambda: None)(), + }, + ) + async def delete_log(self, request: Optional[Union[logging.DeleteLogRequest, dict]] = None, *, diff --git a/tests/integration/goldens/logging/google/cloud/logging_v2/services/logging_service_v2/client.py b/tests/integration/goldens/logging/google/cloud/logging_v2/services/logging_service_v2/client.py index 933daac99f..82234b3856 100755 --- a/tests/integration/goldens/logging/google/cloud/logging_v2/services/logging_service_v2/client.py +++ b/tests/integration/goldens/logging/google/cloud/logging_v2/services/logging_service_v2/client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import os import re from typing import Dict, Callable, Mapping, MutableMapping, MutableSequence, Optional, Iterable, Iterator, Sequence, Tuple, Type, Union, cast @@ -36,6 +37,14 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: # pragma: NO COVER + from google.api_core import client_logging # type: ignore + CLIENT_LOGGING_SUPPORTED = True +except ImportError: + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + from google.api import monitored_resource_pb2 # type: ignore from google.cloud.logging_v2.services.logging_service_v2 import pagers from google.cloud.logging_v2.types import log_entry @@ -490,6 +499,10 @@ def __init__(self, *, # Initialize the universe domain validation. self._is_universe_domain_valid = False + if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER + # Setup logging. + client_logging.initialize_logging() + api_key_value = getattr(self._client_options, "api_key", None) if api_key_value and credentials: raise ValueError("client_options.api_key and credentials are mutually exclusive") @@ -542,6 +555,18 @@ def __init__(self, *, api_audience=self._client_options.api_audience, ) + if "async" not in str(self._transport): + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(std_logging.DEBUG): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.logging_v2.LoggingServiceV2Client`.", + extra = { + "serviceName": "google.logging.v2.LoggingServiceV2", + "universeDomain": getattr(self._transport._credentials, "universe_domain", ""), + "credentialType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}", + "credentialInfo": getattr(self.transport._credentials, "get_cred_info", lambda: None)(), + }, + ) + def delete_log(self, request: Optional[Union[logging.DeleteLogRequest, dict]] = None, *, diff --git a/tests/integration/goldens/logging/google/cloud/logging_v2/services/metrics_service_v2/async_client.py b/tests/integration/goldens/logging/google/cloud/logging_v2/services/metrics_service_v2/async_client.py index d6f06c1f18..82c28b2896 100755 --- a/tests/integration/goldens/logging/google/cloud/logging_v2/services/metrics_service_v2/async_client.py +++ b/tests/integration/goldens/logging/google/cloud/logging_v2/services/metrics_service_v2/async_client.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import logging as std_logging from collections import OrderedDict import re from typing import Dict, Callable, Mapping, MutableMapping, MutableSequence, Optional, Sequence, Tuple, Type, Union @@ -42,6 +43,13 @@ from .transports.grpc_asyncio import MetricsServiceV2GrpcAsyncIOTransport from .client import MetricsServiceV2Client +try: # pragma: NO COVER + from google.api_core import client_logging # type: ignore + CLIENT_LOGGING_SUPPORTED = True +except ImportError: + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) class MetricsServiceV2AsyncClient: """Service for configuring logs-based metrics.""" @@ -228,6 +236,17 @@ def __init__(self, *, ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(std_logging.DEBUG): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.logging_v2.MetricsServiceV2AsyncClient`.", + extra = { + "serviceName": "google.logging.v2.MetricsServiceV2", + "universeDomain": getattr(self._client._transport._credentials, "universe_domain", ""), + "credentialType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}", + "credentialInfo": getattr(self.transport._credentials, "get_cred_info", lambda: None)(), + }, + ) + async def list_log_metrics(self, request: Optional[Union[logging_metrics.ListLogMetricsRequest, dict]] = None, *, diff --git a/tests/integration/goldens/logging/google/cloud/logging_v2/services/metrics_service_v2/client.py b/tests/integration/goldens/logging/google/cloud/logging_v2/services/metrics_service_v2/client.py index 33a386b28b..9c60ff4a04 100755 --- a/tests/integration/goldens/logging/google/cloud/logging_v2/services/metrics_service_v2/client.py +++ b/tests/integration/goldens/logging/google/cloud/logging_v2/services/metrics_service_v2/client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import os import re from typing import Dict, Callable, Mapping, MutableMapping, MutableSequence, Optional, Sequence, Tuple, Type, Union, cast @@ -36,6 +37,14 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: # pragma: NO COVER + from google.api_core import client_logging # type: ignore + CLIENT_LOGGING_SUPPORTED = True +except ImportError: + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + from google.api import distribution_pb2 # type: ignore from google.api import metric_pb2 # type: ignore from google.cloud.logging_v2.services.metrics_service_v2 import pagers @@ -491,6 +500,10 @@ def __init__(self, *, # Initialize the universe domain validation. self._is_universe_domain_valid = False + if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER + # Setup logging. + client_logging.initialize_logging() + api_key_value = getattr(self._client_options, "api_key", None) if api_key_value and credentials: raise ValueError("client_options.api_key and credentials are mutually exclusive") @@ -543,6 +556,18 @@ def __init__(self, *, api_audience=self._client_options.api_audience, ) + if "async" not in str(self._transport): + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(std_logging.DEBUG): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.logging_v2.MetricsServiceV2Client`.", + extra = { + "serviceName": "google.logging.v2.MetricsServiceV2", + "universeDomain": getattr(self._transport._credentials, "universe_domain", ""), + "credentialType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}", + "credentialInfo": getattr(self.transport._credentials, "get_cred_info", lambda: None)(), + }, + ) + def list_log_metrics(self, request: Optional[Union[logging_metrics.ListLogMetricsRequest, dict]] = None, *, diff --git a/tests/integration/goldens/redis/google/cloud/redis_v1/services/cloud_redis/async_client.py b/tests/integration/goldens/redis/google/cloud/redis_v1/services/cloud_redis/async_client.py index 55e33e52bd..cfc8a14b93 100755 --- a/tests/integration/goldens/redis/google/cloud/redis_v1/services/cloud_redis/async_client.py +++ b/tests/integration/goldens/redis/google/cloud/redis_v1/services/cloud_redis/async_client.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import logging as std_logging from collections import OrderedDict import re from typing import Dict, Callable, Mapping, MutableMapping, MutableSequence, Optional, Sequence, Tuple, Type, Union @@ -45,6 +46,13 @@ from .transports.grpc_asyncio import CloudRedisGrpcAsyncIOTransport from .client import CloudRedisClient +try: # pragma: NO COVER + from google.api_core import client_logging # type: ignore + CLIENT_LOGGING_SUPPORTED = True +except ImportError: + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) class CloudRedisAsyncClient: """Configures and manages Cloud Memorystore for Redis instances @@ -255,6 +263,17 @@ def __init__(self, *, ) + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(std_logging.DEBUG): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.redis_v1.CloudRedisAsyncClient`.", + extra = { + "serviceName": "google.cloud.redis.v1.CloudRedis", + "universeDomain": getattr(self._client._transport._credentials, "universe_domain", ""), + "credentialType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}", + "credentialInfo": getattr(self.transport._credentials, "get_cred_info", lambda: None)(), + }, + ) + async def list_instances(self, request: Optional[Union[cloud_redis.ListInstancesRequest, dict]] = None, *, diff --git a/tests/integration/goldens/redis/google/cloud/redis_v1/services/cloud_redis/client.py b/tests/integration/goldens/redis/google/cloud/redis_v1/services/cloud_redis/client.py index 895f5c98d0..f69d514e00 100755 --- a/tests/integration/goldens/redis/google/cloud/redis_v1/services/cloud_redis/client.py +++ b/tests/integration/goldens/redis/google/cloud/redis_v1/services/cloud_redis/client.py @@ -14,6 +14,7 @@ # limitations under the License. # from collections import OrderedDict +import logging as std_logging import os import re from typing import Dict, Callable, Mapping, MutableMapping, MutableSequence, Optional, Sequence, Tuple, Type, Union, cast @@ -36,6 +37,14 @@ except AttributeError: # pragma: NO COVER OptionalRetry = Union[retries.Retry, object, None] # type: ignore +try: # pragma: NO COVER + from google.api_core import client_logging # type: ignore + CLIENT_LOGGING_SUPPORTED = True +except ImportError: + CLIENT_LOGGING_SUPPORTED = False + +_LOGGER = std_logging.getLogger(__name__) + from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.location import locations_pb2 # type: ignore @@ -530,6 +539,10 @@ def __init__(self, *, # Initialize the universe domain validation. self._is_universe_domain_valid = False + if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER + # Setup logging. + client_logging.initialize_logging() + api_key_value = getattr(self._client_options, "api_key", None) if api_key_value and credentials: raise ValueError("client_options.api_key and credentials are mutually exclusive") @@ -604,6 +617,18 @@ def __init__(self, *, api_audience=self._client_options.api_audience, ) + if "async" not in str(self._transport): + if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(std_logging.DEBUG): # pragma: NO COVER + _LOGGER.debug( + "Created client `google.cloud.redis_v1.CloudRedisClient`.", + extra = { + "serviceName": "google.cloud.redis.v1.CloudRedis", + "universeDomain": getattr(self._transport._credentials, "universe_domain", ""), + "credentialType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}", + "credentialInfo": getattr(self.transport._credentials, "get_cred_info", lambda: None)(), + }, + ) + def list_instances(self, request: Optional[Union[cloud_redis.ListInstancesRequest, dict]] = None, *, diff --git a/tests/unit/schema/test_metadata.py b/tests/unit/schema/test_metadata.py index df8967da71..3189b3a9fd 100644 --- a/tests/unit/schema/test_metadata.py +++ b/tests/unit/schema/test_metadata.py @@ -97,6 +97,12 @@ def test_proto_package_version_parsing(): addr = metadata.Address(package=("bah", "v20p1", "baj", "v3")) assert addr.convert_to_versioned_package() == ("bah", "v20p1", "baj_v3") + addr = metadata.Address(package=("bab", "v1")) + assert addr.proto_package_versioned == "bab_v1" + + addr = metadata.Address(package=("bah", "v20p1", "baj", "v3")) + assert addr.proto_package_versioned == "bah.v20p1.baj_v3" + def test_address_child_no_parent(): addr = metadata.Address(package=('foo', 'bar'), module='baz')