|
41 | 41 |
|
42 | 42 | _GENAI_MODULES_TELEMETRY_HEADER = "vertex-genai-modules" |
43 | 43 |
|
44 | | -genai_append_method = _api_client.append_library_version_headers |
45 | | - |
46 | | - |
47 | | -def _add_tracking_headers(headers: dict[str, str]) -> None: |
48 | | - """Adds Vertex Gen AI tracking headers.""" |
49 | | - is_vertex = headers.get( |
50 | | - "x-goog-vertex-sdk" |
51 | | - ) == "true" or "vertex-genai-modules" in headers.get("user-agent", "") |
52 | | - if is_vertex: |
53 | | - tracking_label = f"{_GENAI_MODULES_TELEMETRY_HEADER}/{aip_version.__version__}" |
54 | | - |
55 | | - headers["user-agent"] = tracking_label |
56 | | - headers["x-goog-api-client"] = tracking_label |
57 | | - |
58 | | - headers.pop("x-goog-vertex-sdk", None) |
59 | | - else: |
60 | | - genai_append_method(headers) |
61 | | - |
62 | | - |
63 | | -_api_client.append_library_version_headers = _add_tracking_headers |
64 | | - |
65 | 44 |
|
66 | 45 | class AsyncClient: |
67 | 46 | """Async Gen AI Client for the Vertex SDK.""" |
@@ -229,7 +208,24 @@ def __init__( |
229 | 208 | http_options = types.HttpOptions() |
230 | 209 | if http_options.headers is None: |
231 | 210 | http_options.headers = {} |
232 | | - http_options.headers["x-goog-vertex-sdk"] = "true" |
| 211 | + |
| 212 | + tracking_label = ( |
| 213 | + f"{_GENAI_MODULES_TELEMETRY_HEADER}/{aip_version.__version__}" |
| 214 | + ) |
| 215 | + |
| 216 | + if "user-agent" in http_options.headers: |
| 217 | + http_options.headers["user-agent"] = ( |
| 218 | + f"{http_options.headers['user-agent']} {tracking_label}" |
| 219 | + ) |
| 220 | + else: |
| 221 | + http_options.headers["user-agent"] = tracking_label |
| 222 | + |
| 223 | + if "x-goog-api-client" in http_options.headers: |
| 224 | + http_options.headers["x-goog-api-client"] = ( |
| 225 | + f"{http_options.headers['x-goog-api-client']} {tracking_label}" |
| 226 | + ) |
| 227 | + else: |
| 228 | + http_options.headers["x-goog-api-client"] = tracking_label |
233 | 229 |
|
234 | 230 | self._api_client = genai_client.Client._get_api_client( |
235 | 231 | vertexai=True, |
|
0 commit comments