Skip to content

Commit 388ebe9

Browse files
sararobcopybara-github
authored andcommitted
chore: Update headers
PiperOrigin-RevId: 908716648
1 parent f48e54b commit 388ebe9

2 files changed

Lines changed: 12 additions & 13 deletions

File tree

tests/unit/vertexai/genai/replays/conftest.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@
2323
client as vertexai_genai_client_module,
2424
)
2525
from vertexai._genai import _agent_engines_utils
26-
from vertexai._genai.client import (
27-
_GENAI_MODULES_TELEMETRY_HEADER,
28-
)
29-
from google.cloud.aiplatform import version as aip_version
3026
from google.cloud import storage, bigquery
3127
from google.genai import _replay_api_client
3228
from google.genai import types as genai_types
@@ -265,10 +261,6 @@ def client(use_vertex, replays_prefix, http_options, request):
265261
if http_options.headers is None:
266262
http_options.headers = {}
267263

268-
tracking_label = f"{_GENAI_MODULES_TELEMETRY_HEADER}/{aip_version.__version__}"
269-
http_options.headers["user-agent"] = tracking_label
270-
http_options.headers["x-goog-api-client"] = tracking_label
271-
272264
replay_client = _replay_api_client.ReplayApiClient(
273265
mode=mode,
274266
replay_id=replay_id,

vertexai/_genai/client.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import asyncio
1717
import importlib
18+
import sys
1819
from typing import Optional, Union, TYPE_CHECKING
1920
from types import TracebackType, ModuleType
2021

@@ -23,6 +24,8 @@
2324
from google.genai import _common
2425
from google.genai import client as genai_client
2526
from google.genai import types
27+
from google.genai import _api_client as genai_api_client
28+
from google.genai import version as genai_version
2629
from . import live
2730

2831
if TYPE_CHECKING:
@@ -208,21 +211,25 @@ def __init__(
208211
if http_options.headers is None:
209212
http_options.headers = {}
210213

211-
tracking_label = f"{_GENAI_MODULES_TELEMETRY_HEADER}/{aip_version.__version__}"
214+
genai_sdk_version = genai_version.__version__
215+
module_version = aip_version.__version__
216+
python_version = sys.version.split()[0]
217+
218+
agent_platform_header = f"google-genai-sdk/{genai_sdk_version}+{_GENAI_MODULES_TELEMETRY_HEADER}/{module_version} gl-python/{python_version}"
212219

213220
if "user-agent" in http_options.headers:
214221
http_options.headers["user-agent"] = (
215-
f"{http_options.headers['user-agent']} {tracking_label}"
222+
f"{agent_platform_header} " + http_options.headers["user-agent"]
216223
)
217224
else:
218-
http_options.headers["user-agent"] = tracking_label
225+
http_options.headers["user-agent"] = agent_platform_header
219226

220227
if "x-goog-api-client" in http_options.headers:
221228
http_options.headers["x-goog-api-client"] = (
222-
f"{http_options.headers['x-goog-api-client']} {tracking_label}"
229+
f"{agent_platform_header} " + http_options.headers["x-goog-api-client"]
223230
)
224231
else:
225-
http_options.headers["x-goog-api-client"] = tracking_label
232+
http_options.headers["x-goog-api-client"] = agent_platform_header
226233

227234
self._api_client = genai_client.Client._get_api_client(
228235
vertexai=True,

0 commit comments

Comments
 (0)