|
41 | 41 |
|
42 | 42 | _GENAI_MODULES_TELEMETRY_HEADER = "vertex-genai-modules" |
43 | 43 |
|
| 44 | +genai_append_method = _api_client.append_library_version_headers |
| 45 | + |
44 | 46 |
|
45 | 47 | def _add_tracking_headers(headers: dict[str, str]) -> None: |
46 | 48 | """Appends Vertex Gen AI modules tracking information to the request headers.""" |
| 49 | + if headers.get("x-goog-vertex-sdk", "") == "true": |
47 | 50 |
|
48 | | - tracking_label = f"{_GENAI_MODULES_TELEMETRY_HEADER}/{aip_version.__version__}" |
| 51 | + tracking_label = f"{_GENAI_MODULES_TELEMETRY_HEADER}/{aip_version.__version__}" |
49 | 52 |
|
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() |
53 | 56 |
|
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 |
57 | 63 |
|
58 | 64 |
|
59 | 65 | _api_client.append_library_version_headers = _add_tracking_headers |
@@ -221,6 +227,9 @@ def __init__( |
221 | 227 | self._debug_config = debug_config or genai_client.DebugConfig() |
222 | 228 | if isinstance(http_options, dict): |
223 | 229 | 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" |
224 | 233 |
|
225 | 234 | self._api_client = genai_client.Client._get_api_client( |
226 | 235 | vertexai=True, |
|
0 commit comments