3535from google .cloud .logging_v2 .sink import Sink
3636from google .cloud .logging_v2 .metric import Metric
3737
38+ from google .api_core import client_info
39+ from google .api_core import gapic_v1
40+
3841
3942class _LoggingAPI (object ):
4043 """Helper mapping logging-related APIs."""
@@ -562,6 +565,22 @@ def _log_entry_mapping_to_pb(mapping):
562565 return LogEntryPB (entry_pb )
563566
564567
568+ def _client_info_to_gapic (input_info ):
569+ """
570+ Helper function to convert api_core.client_info to
571+ api_core.gapic_v1.client_info subclass
572+ """
573+ return gapic_v1 .client_info .ClientInfo (
574+ python_version = input_info .python_version ,
575+ grpc_version = input_info .grpc_version ,
576+ api_core_version = input_info .api_core_version ,
577+ gapic_version = input_info .gapic_version ,
578+ client_library_version = input_info .client_library_version ,
579+ user_agent = input_info .user_agent ,
580+ rest_version = input_info .rest_version ,
581+ )
582+
583+
565584def make_logging_api (client ):
566585 """Create an instance of the Logging API adapter.
567586
@@ -572,9 +591,14 @@ def make_logging_api(client):
572591 Returns:
573592 _LoggingAPI: A metrics API instance with the proper credentials.
574593 """
594+ info = client ._client_info
595+ if type (info ) == client_info .ClientInfo :
596+ # convert into gapic-compatible subclass
597+ info = _client_info_to_gapic (info )
598+
575599 generated = LoggingServiceV2Client (
576600 credentials = client ._credentials ,
577- client_info = client . _client_info ,
601+ client_info = info ,
578602 client_options = client ._client_options ,
579603 )
580604 return _LoggingAPI (generated , client )
@@ -590,9 +614,14 @@ def make_metrics_api(client):
590614 Returns:
591615 _MetricsAPI: A metrics API instance with the proper credentials.
592616 """
617+ info = client ._client_info
618+ if type (info ) == client_info .ClientInfo :
619+ # convert into gapic-compatible subclass
620+ info = _client_info_to_gapic (info )
621+
593622 generated = MetricsServiceV2Client (
594623 credentials = client ._credentials ,
595- client_info = client . _client_info ,
624+ client_info = info ,
596625 client_options = client ._client_options ,
597626 )
598627 return _MetricsAPI (generated , client )
@@ -608,9 +637,14 @@ def make_sinks_api(client):
608637 Returns:
609638 _SinksAPI: A metrics API instance with the proper credentials.
610639 """
640+ info = client ._client_info
641+ if type (info ) == client_info .ClientInfo :
642+ # convert into gapic-compatible subclass
643+ info = _client_info_to_gapic (info )
644+
611645 generated = ConfigServiceV2Client (
612646 credentials = client ._credentials ,
613- client_info = client . _client_info ,
647+ client_info = info ,
614648 client_options = client ._client_options ,
615649 )
616650 return _SinksAPI (generated , client )
0 commit comments