Skip to content

Commit c9d5334

Browse files
committed
chore: add debug logging for token length and expiry
1 parent 4b5f2b0 commit c9d5334

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

google/cloud/alloydbconnector/connector.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
from __future__ import annotations
1616

1717
import asyncio
18+
from datetime import datetime
19+
from datetime import timezone
1820
from functools import partial
1921
import io
2022
import logging
@@ -259,6 +261,7 @@ async def connect_async(self, instance_uri: str, driver: str, **kwargs: Any) ->
259261
try:
260262
metadata_partial = partial(
261263
self.metadata_exchange,
264+
instance_uri,
262265
ip_address,
263266
await conn_info.create_ssl_context(),
264267
enable_iam_auth,
@@ -272,7 +275,11 @@ async def connect_async(self, instance_uri: str, driver: str, **kwargs: Any) ->
272275
raise
273276

274277
def metadata_exchange(
275-
self, ip_address: str, ctx: ssl.SSLContext, enable_iam_auth: bool
278+
self,
279+
instance_uri: str,
280+
ip_address: str,
281+
ctx: ssl.SSLContext,
282+
enable_iam_auth: bool,
276283
) -> ssl.SSLSocket:
277284
"""
278285
Sends metadata about the connection prior to the database
@@ -318,6 +325,13 @@ def metadata_exchange(
318325
if not self._db_credentials.token_state == TokenState.FRESH:
319326
self._db_credentials.refresh(requests.Request())
320327

328+
logger.debug(
329+
f"['{instance_uri}']: Metadata exchange started "
330+
f"now={datetime.now(timezone.utc).isoformat()}, "
331+
f"token expiration={self._db_credentials.expiry.replace(tzinfo=timezone.utc).isoformat()}, "
332+
f"token size={len(self._db_credentials.token)}"
333+
)
334+
321335
# form metadata exchange request
322336
req = connectorspb.MetadataExchangeRequest(
323337
user_agent=f"{self._client._user_agent}", # type: ignore

0 commit comments

Comments
 (0)