Skip to content

Commit 118bd96

Browse files
authored
feat: Add protobuf runtime version to x-goog-api-client header (#812)
* for testing purposes * lint
1 parent 66d84a3 commit 118bd96

File tree

5 files changed

+17
-2
lines changed

5 files changed

+17
-2
lines changed

google/api_core/client_info.py

+6
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class ClientInfo(object):
5959
Recommended format: ``application-or-tool-ID/major.minor.version``.
6060
rest_version (Optional[str]): A string with labeled versions of the
6161
dependencies used for REST transport.
62+
protobuf_runtime_version (Optional[str]): The protobuf runtime version.
6263
"""
6364

6465
def __init__(
@@ -70,6 +71,7 @@ def __init__(
7071
client_library_version=None,
7172
user_agent=None,
7273
rest_version=None,
74+
protobuf_runtime_version=None,
7375
):
7476
self.python_version = python_version
7577
self.grpc_version = grpc_version
@@ -78,6 +80,7 @@ def __init__(
7880
self.client_library_version = client_library_version
7981
self.user_agent = user_agent
8082
self.rest_version = rest_version
83+
self.protobuf_runtime_version = protobuf_runtime_version
8184

8285
def to_user_agent(self):
8386
"""Returns the user-agent string for this client info."""
@@ -105,4 +108,7 @@ def to_user_agent(self):
105108
if self.client_library_version is not None:
106109
ua += "gccl/{client_library_version} "
107110

111+
if self.protobuf_runtime_version is not None:
112+
ua += "pb/{protobuf_runtime_version} "
113+
108114
return ua.format(**self.__dict__).strip()

google/api_core/gapic_v1/client_info.py

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class ClientInfo(client_info.ClientInfo):
4747
Recommended format: ``application-or-tool-ID/major.minor.version``.
4848
rest_version (Optional[str]): A string with labeled versions of the
4949
dependencies used for REST transport.
50+
protobuf_runtime_version (Optional[str]): The protobuf runtime version.
5051
"""
5152

5253
def to_grpc_metadata(self):

tests/asyncio/gapic/test_method_async.py

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ async def test_wrap_method_with_custom_client_info():
8181
api_core_version=3,
8282
gapic_version=4,
8383
client_library_version=5,
84+
protobuf_runtime_version=6,
8485
)
8586
fake_call = grpc_helpers_async.FakeUnaryUnaryCall()
8687
method = mock.Mock(spec=aio.UnaryUnaryMultiCallable, return_value=fake_call)

tests/unit/gapic/test_method.py

+1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ def test_wrap_method_with_custom_client_info():
7676
api_core_version=3,
7777
gapic_version=4,
7878
client_library_version=5,
79+
protobuf_runtime_version=6,
7980
)
8081
method = mock.Mock(spec=["__call__"])
8182

tests/unit/test_client_info.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def test_constructor_options():
4646
client_library_version="5",
4747
user_agent="6",
4848
rest_version="7",
49+
protobuf_runtime_version="8",
4950
)
5051

5152
assert info.python_version == "1"
@@ -55,11 +56,15 @@ def test_constructor_options():
5556
assert info.client_library_version == "5"
5657
assert info.user_agent == "6"
5758
assert info.rest_version == "7"
59+
assert info.protobuf_runtime_version == "8"
5860

5961

6062
def test_to_user_agent_minimal():
6163
info = client_info.ClientInfo(
62-
python_version="1", api_core_version="2", grpc_version=None
64+
python_version="1",
65+
api_core_version="2",
66+
grpc_version=None,
67+
protobuf_runtime_version=None,
6368
)
6469

6570
user_agent = info.to_user_agent()
@@ -75,11 +80,12 @@ def test_to_user_agent_full():
7580
gapic_version="4",
7681
client_library_version="5",
7782
user_agent="app-name/1.0",
83+
protobuf_runtime_version="6",
7884
)
7985

8086
user_agent = info.to_user_agent()
8187

82-
assert user_agent == "app-name/1.0 gl-python/1 grpc/2 gax/3 gapic/4 gccl/5"
88+
assert user_agent == "app-name/1.0 gl-python/1 grpc/2 gax/3 gapic/4 gccl/5 pb/6"
8389

8490

8591
def test_to_user_agent_rest():

0 commit comments

Comments
 (0)