Skip to content

Commit 7539e6a

Browse files
sararobcopybara-github
authored andcommitted
chore: telemetry update
PiperOrigin-RevId: 881123107
1 parent eacc86c commit 7539e6a

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

vertexai/_genai/client.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,25 @@
4141

4242
_GENAI_MODULES_TELEMETRY_HEADER = "vertex-genai-modules"
4343

44+
genai_append_method = _api_client.append_library_version_headers
45+
4446

4547
def _add_tracking_headers(headers: dict[str, str]) -> None:
4648
"""Appends Vertex Gen AI modules tracking information to the request headers."""
49+
if headers.get("x-goog-vertex-sdk", "") == "true":
4750

48-
tracking_label = f"{_GENAI_MODULES_TELEMETRY_HEADER}/{aip_version.__version__}"
51+
tracking_label = f"{_GENAI_MODULES_TELEMETRY_HEADER}/{aip_version.__version__}"
4952

50-
user_agent = headers.get("user-agent", "")
51-
if tracking_label not in user_agent:
52-
headers["user-agent"] = f"{user_agent} {tracking_label}".strip()
53+
user_agent = headers.get("user-agent", "")
54+
if tracking_label not in user_agent:
55+
headers["user-agent"] = f"{user_agent} {tracking_label}".strip()
5356

54-
api_client = headers.get("x-goog-api-client", "")
55-
if tracking_label not in api_client:
56-
headers["x-goog-api-client"] = f"{api_client} {tracking_label}".strip()
57+
api_client = headers.get("x-goog-api-client", "")
58+
if tracking_label not in api_client:
59+
headers["x-goog-api-client"] = f"{api_client} {tracking_label}".strip()
60+
del headers["x-goog-vertex-sdk"]
61+
else:
62+
_api_client.append_library_version_headers = genai_append_method
5763

5864

5965
_api_client.append_library_version_headers = _add_tracking_headers
@@ -221,6 +227,9 @@ def __init__(
221227
self._debug_config = debug_config or genai_client.DebugConfig()
222228
if isinstance(http_options, dict):
223229
http_options = types.HttpOptions(**http_options)
230+
if http_options is None:
231+
http_options = types.HttpOptions()
232+
http_options.headers["x-goog-vertex-sdk"] = "true"
224233

225234
self._api_client = genai_client.Client._get_api_client(
226235
vertexai=True,

0 commit comments

Comments
 (0)