@@ -1949,6 +1949,7 @@ def __init__(
19491949 table_id : Optional [str ] = None ,
19501950 config : Optional [BigQueryLoggerConfig ] = None ,
19511951 location : str = "US" ,
1952+ credentials : Optional [google .auth .credentials .Credentials ] = None ,
19521953 ** kwargs ,
19531954 ) -> None :
19541955 """Initializes the instance.
@@ -1959,6 +1960,8 @@ def __init__(
19591960 table_id: BigQuery table ID (optional, overrides config).
19601961 config: BigQueryLoggerConfig (optional).
19611962 location: BigQuery location (default: "US").
1963+ credentials: Google Auth credentials (optional). If None, uses
1964+ Application Default Credentials.
19621965 **kwargs: Additional configuration parameters for BigQueryLoggerConfig.
19631966 """
19641967 super ().__init__ (name = "bigquery_agent_analytics" )
@@ -1985,6 +1988,7 @@ def __init__(
19851988 self ._startup_error : Optional [Exception ] = None
19861989 self ._is_shutting_down = False
19871990 self ._setup_lock = None
1991+ self ._credentials = credentials
19881992 self .client = None
19891993 self ._loop_state_by_loop : dict [asyncio .AbstractEventLoop , _LoopState ] = {}
19901994 self ._write_stream_name = None # Resolved stream name
@@ -2097,15 +2101,16 @@ async def _get_loop_state(self) -> _LoopState:
20972101 # grpc.aio clients are loop-bound, so we create one per event loop.
20982102
20992103 def get_credentials ():
2100- creds , project_id = google .auth .default (
2104+ creds , _ = google .auth .default (
21012105 scopes = ["https://www.googleapis.com/auth/cloud-platform" ]
21022106 )
2103- return creds , project_id
2107+ return creds
21042108
2105- creds , project_id = await loop .run_in_executor (
2106- self ._executor , get_credentials
2107- )
2108- quota_project_id = getattr (creds , "quota_project_id" , None )
2109+ if self ._credentials is None :
2110+ self ._credentials = await loop .run_in_executor (
2111+ self ._executor , get_credentials
2112+ )
2113+ quota_project_id = getattr (self ._credentials , "quota_project_id" , None )
21092114 options = (
21102115 client_options .ClientOptions (quota_project_id = quota_project_id )
21112116 if quota_project_id
@@ -2119,7 +2124,7 @@ def get_credentials():
21192124 client_info = gapic_client_info .ClientInfo (user_agent = " " .join (user_agents ))
21202125
21212126 write_client = BigQueryWriteAsyncClient (
2122- credentials = creds ,
2127+ credentials = self . _credentials ,
21232128 client_info = client_info ,
21242129 client_options = options ,
21252130 )
@@ -2173,7 +2178,9 @@ async def _lazy_setup(self, **kwargs) -> None:
21732178 self .client = await loop .run_in_executor (
21742179 self ._executor ,
21752180 lambda : bigquery .Client (
2176- project = self .project_id , location = self .location
2181+ project = self .project_id ,
2182+ location = self .location ,
2183+ credentials = self ._credentials ,
21772184 ),
21782185 )
21792186
@@ -2193,7 +2200,9 @@ async def _lazy_setup(self, **kwargs) -> None:
21932200 self .project_id ,
21942201 self .config .gcs_bucket_name ,
21952202 self ._executor ,
2196- storage_client = kwargs .get ("storage_client" ),
2203+ storage_client = storage .Client (
2204+ project = self .project_id , credentials = self ._credentials
2205+ ),
21972206 )
21982207
21992208 self .parser = HybridContentParser (
0 commit comments