@@ -318,8 +318,10 @@ def _warn_missing_dependency(
318318 return None
319319
320320 def _detect_cloud_resource_id (project_id : str ) -> Optional [str ]:
321- location = os .getenv ("GOOGLE_CLOUD_LOCATION" , None )
322- agent_engine_id = os .getenv ("GOOGLE_CLOUD_AGENT_ENGINE_ID" , None )
321+ location = os .getenv ("GOOGLE_CLOUD_AGENT_ENGINE_LOCATION" , "" ) or os .getenv (
322+ "GOOGLE_CLOUD_LOCATION" , ""
323+ )
324+ agent_engine_id = os .getenv ("GOOGLE_CLOUD_AGENT_ENGINE_ID" )
323325 if all (v is not None for v in (location , agent_engine_id )):
324326 return f"//aiplatform.googleapis.com/projects/{ project_id } /locations/{ location } /reasoningEngines/{ agent_engine_id } "
325327 return None
@@ -359,7 +361,10 @@ def _detect_cloud_resource_id(project_id: str) -> Optional[str]:
359361 "cloud.platform" : "gcp.agent_engine" ,
360362 "service.name" : os .getenv ("GOOGLE_CLOUD_AGENT_ENGINE_ID" , "" ),
361363 "service.instance.id" : f"{ uuid .uuid4 ().hex } -{ os .getpid ()} " ,
362- "cloud.region" : os .getenv ("GOOGLE_CLOUD_LOCATION" , "" ),
364+ "cloud.region" : (
365+ os .getenv ("GOOGLE_CLOUD_AGENT_ENGINE_LOCATION" , "" )
366+ or os .getenv ("GOOGLE_CLOUD_LOCATION" , "" )
367+ ),
363368 }
364369 | (
365370 {"cloud.resource_id" : cloud_resource_id }
@@ -772,11 +777,15 @@ def set_up(self):
772777 os .environ ["GOOGLE_CLOUD_PROJECT" ] = project
773778 location = self ._tmpl_attrs .get ("location" )
774779 if location :
775- os .environ ["GOOGLE_CLOUD_LOCATION" ] = location
780+ if "GOOGLE_CLOUD_AGENT_ENGINE_LOCATION" not in os .environ :
781+ os .environ ["GOOGLE_CLOUD_AGENT_ENGINE_LOCATION" ] = location
782+ if "GOOGLE_CLOUD_LOCATION" not in os .environ :
783+ os .environ ["GOOGLE_CLOUD_LOCATION" ] = location
776784 express_mode_api_key = self ._tmpl_attrs .get ("express_mode_api_key" )
777785 if express_mode_api_key and not project :
778786 os .environ ["GOOGLE_API_KEY" ] = express_mode_api_key
779787 # Clear location and project env vars if express mode api key is provided.
788+ os .environ .pop ("GOOGLE_CLOUD_AGENT_ENGINE_LOCATION" , None )
780789 os .environ .pop ("GOOGLE_CLOUD_LOCATION" , None )
781790 os .environ .pop ("GOOGLE_CLOUD_PROJECT" , None )
782791 location = None
0 commit comments