Skip to content

Commit 57845f5

Browse files
committed
renamed connection_uuid as session_id_hex
Signed-off-by: Sai Shree Pradhan <saishree.pradhan@databricks.com>
1 parent db9c2c7 commit 57845f5

File tree

5 files changed

+98
-98
lines changed

5 files changed

+98
-98
lines changed

src/databricks/sql/client.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -309,13 +309,13 @@ def read(self) -> Optional[OAuthToken]:
309309

310310
initialize_telemetry_client(
311311
telemetry_enabled=self.telemetry_enabled,
312-
connection_uuid=self.get_session_id_hex(),
312+
session_id_hex=self.get_session_id_hex(),
313313
auth_provider=auth_provider,
314314
host_url=self.host,
315315
)
316316

317317
self._telemetry_client = get_telemetry_client(
318-
connection_uuid=self.get_session_id_hex()
318+
session_id_hex=self.get_session_id_hex()
319319
)
320320

321321
driver_connection_params = DriverConnectionParameters(
@@ -427,7 +427,7 @@ def cursor(
427427
if not self.open:
428428
raise InterfaceError(
429429
"Cannot create cursor from closed connection",
430-
connection_uuid=self.get_session_id_hex(),
430+
session_id_hex=self.get_session_id_hex(),
431431
)
432432

433433
cursor = Cursor(
@@ -480,7 +480,7 @@ def commit(self):
480480
def rollback(self):
481481
raise NotSupportedError(
482482
"Transactions are not supported on Databricks",
483-
connection_uuid=self.get_session_id_hex(),
483+
session_id_hex=self.get_session_id_hex(),
484484
)
485485

486486

@@ -535,7 +535,7 @@ def __iter__(self):
535535
else:
536536
raise ProgrammingError(
537537
"There is no active result set",
538-
connection_uuid=self.connection.get_session_id_hex(),
538+
session_id_hex=self.connection.get_session_id_hex(),
539539
)
540540

541541
def _determine_parameter_approach(
@@ -675,7 +675,7 @@ def _check_not_closed(self):
675675
if not self.open:
676676
raise InterfaceError(
677677
"Attempting operation on closed cursor",
678-
connection_uuid=self.connection.get_session_id_hex(),
678+
session_id_hex=self.connection.get_session_id_hex(),
679679
)
680680

681681
def _handle_staging_operation(
@@ -695,7 +695,7 @@ def _handle_staging_operation(
695695
else:
696696
raise ProgrammingError(
697697
"You must provide at least one staging_allowed_local_path when initialising a connection to perform ingestion commands",
698-
connection_uuid=self.connection.get_session_id_hex(),
698+
session_id_hex=self.connection.get_session_id_hex(),
699699
)
700700

701701
abs_staging_allowed_local_paths = [
@@ -725,7 +725,7 @@ def _handle_staging_operation(
725725
if not allow_operation:
726726
raise ProgrammingError(
727727
"Local file operations are restricted to paths within the configured staging_allowed_local_path",
728-
connection_uuid=self.connection.get_session_id_hex(),
728+
session_id_hex=self.connection.get_session_id_hex(),
729729
)
730730

731731
# May be real headers, or could be json string
@@ -756,7 +756,7 @@ def _handle_staging_operation(
756756
raise ProgrammingError(
757757
f"Operation {row.operation} is not supported. "
758758
+ "Supported operations are GET, PUT, and REMOVE",
759-
connection_uuid=self.connection.get_session_id_hex(),
759+
session_id_hex=self.connection.get_session_id_hex(),
760760
)
761761

762762
def _handle_staging_put(
@@ -770,7 +770,7 @@ def _handle_staging_put(
770770
if local_file is None:
771771
raise ProgrammingError(
772772
"Cannot perform PUT without specifying a local_file",
773-
connection_uuid=self.connection.get_session_id_hex(),
773+
session_id_hex=self.connection.get_session_id_hex(),
774774
)
775775

776776
with open(local_file, "rb") as fh:
@@ -789,7 +789,7 @@ def _handle_staging_put(
789789
if r.status_code not in [OK, CREATED, NO_CONTENT, ACCEPTED]:
790790
raise OperationalError(
791791
f"Staging operation over HTTP was unsuccessful: {r.status_code}-{r.text}",
792-
connection_uuid=self.connection.get_session_id_hex(),
792+
session_id_hex=self.connection.get_session_id_hex(),
793793
)
794794

795795
if r.status_code == ACCEPTED:
@@ -809,7 +809,7 @@ def _handle_staging_get(
809809
if local_file is None:
810810
raise ProgrammingError(
811811
"Cannot perform GET without specifying a local_file",
812-
connection_uuid=self.connection.get_session_id_hex(),
812+
session_id_hex=self.connection.get_session_id_hex(),
813813
)
814814

815815
r = requests.get(url=presigned_url, headers=headers)
@@ -819,7 +819,7 @@ def _handle_staging_get(
819819
if not r.ok:
820820
raise OperationalError(
821821
f"Staging operation over HTTP was unsuccessful: {r.status_code}-{r.text}",
822-
connection_uuid=self.connection.get_session_id_hex(),
822+
session_id_hex=self.connection.get_session_id_hex(),
823823
)
824824

825825
with open(local_file, "wb") as fp:
@@ -835,7 +835,7 @@ def _handle_staging_remove(
835835
if not r.ok:
836836
raise OperationalError(
837837
f"Staging operation over HTTP was unsuccessful: {r.status_code}-{r.text}",
838-
connection_uuid=self.connection.get_session_id_hex(),
838+
session_id_hex=self.connection.get_session_id_hex(),
839839
)
840840

841841
def execute(
@@ -1035,7 +1035,7 @@ def get_async_execution_result(self):
10351035
else:
10361036
raise OperationalError(
10371037
f"get_execution_result failed with Operation status {operation_state}",
1038-
connection_uuid=self.connection.get_session_id_hex(),
1038+
session_id_hex=self.connection.get_session_id_hex(),
10391039
)
10401040

10411041
def executemany(self, operation, seq_of_parameters):
@@ -1187,7 +1187,7 @@ def fetchall(self) -> List[Row]:
11871187
else:
11881188
raise ProgrammingError(
11891189
"There is no active result set",
1190-
connection_uuid=self.connection.get_session_id_hex(),
1190+
session_id_hex=self.connection.get_session_id_hex(),
11911191
)
11921192

11931193
def fetchone(self) -> Optional[Row]:
@@ -1204,7 +1204,7 @@ def fetchone(self) -> Optional[Row]:
12041204
else:
12051205
raise ProgrammingError(
12061206
"There is no active result set",
1207-
connection_uuid=self.connection.get_session_id_hex(),
1207+
session_id_hex=self.connection.get_session_id_hex(),
12081208
)
12091209

12101210
def fetchmany(self, size: int) -> List[Row]:
@@ -1229,7 +1229,7 @@ def fetchmany(self, size: int) -> List[Row]:
12291229
else:
12301230
raise ProgrammingError(
12311231
"There is no active result set",
1232-
connection_uuid=self.connection.get_session_id_hex(),
1232+
session_id_hex=self.connection.get_session_id_hex(),
12331233
)
12341234

12351235
def fetchall_arrow(self) -> "pyarrow.Table":
@@ -1239,7 +1239,7 @@ def fetchall_arrow(self) -> "pyarrow.Table":
12391239
else:
12401240
raise ProgrammingError(
12411241
"There is no active result set",
1242-
connection_uuid=self.connection.get_session_id_hex(),
1242+
session_id_hex=self.connection.get_session_id_hex(),
12431243
)
12441244

12451245
def fetchmany_arrow(self, size) -> "pyarrow.Table":
@@ -1249,7 +1249,7 @@ def fetchmany_arrow(self, size) -> "pyarrow.Table":
12491249
else:
12501250
raise ProgrammingError(
12511251
"There is no active result set",
1252-
connection_uuid=self.connection.get_session_id_hex(),
1252+
session_id_hex=self.connection.get_session_id_hex(),
12531253
)
12541254

12551255
def cancel(self) -> None:

src/databricks/sql/exc.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ class Error(Exception):
1414
"""
1515

1616
def __init__(
17-
self, message=None, context=None, connection_uuid=None, *args, **kwargs
17+
self, message=None, context=None, session_id_hex=None, *args, **kwargs
1818
):
1919
super().__init__(message, *args, **kwargs)
2020
self.message = message
2121
self.context = context or {}
2222

2323
error_name = self.__class__.__name__
24-
if connection_uuid:
25-
telemetry_client = get_telemetry_client(connection_uuid)
24+
if session_id_hex:
25+
telemetry_client = get_telemetry_client(session_id_hex)
2626
telemetry_client.export_failure_log(error_name, self.message)
2727

2828
def __str__(self):

src/databricks/sql/telemetry/telemetry_client.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,15 @@ class TelemetryClient(BaseTelemetryClient):
140140
def __init__(
141141
self,
142142
telemetry_enabled,
143-
connection_uuid,
143+
session_id_hex,
144144
auth_provider,
145145
host_url,
146146
executor,
147147
):
148-
logger.debug("Initializing TelemetryClient for connection: %s", connection_uuid)
148+
logger.debug("Initializing TelemetryClient for connection: %s", session_id_hex)
149149
self._telemetry_enabled = telemetry_enabled
150150
self._batch_size = 10 # TODO: Decide on batch size
151-
self._connection_uuid = connection_uuid
151+
self._session_id_hex = session_id_hex
152152
self._auth_provider = auth_provider
153153
self._user_agent = None
154154
self._events_batch = []
@@ -159,7 +159,7 @@ def __init__(
159159

160160
def _export_event(self, event):
161161
"""Add an event to the batch queue and flush if batch is full"""
162-
logger.debug("Exporting event for connection %s", self._connection_uuid)
162+
logger.debug("Exporting event for connection %s", self._session_id_hex)
163163
with self._lock:
164164
self._events_batch.append(event)
165165
if len(self._events_batch) >= self._batch_size:
@@ -230,7 +230,7 @@ def _telemetry_request_callback(self, future):
230230

231231
def export_initial_telemetry_log(self, driver_connection_params, user_agent):
232232
logger.debug(
233-
"Exporting initial telemetry log for connection %s", self._connection_uuid
233+
"Exporting initial telemetry log for connection %s", self._session_id_hex
234234
)
235235

236236
try:
@@ -247,7 +247,7 @@ def export_initial_telemetry_log(self, driver_connection_params, user_agent):
247247
),
248248
entry=FrontendLogEntry(
249249
sql_driver_log=TelemetryEvent(
250-
session_id=self._connection_uuid,
250+
session_id=self._session_id_hex,
251251
system_configuration=TelemetryHelper.get_driver_system_configuration(),
252252
driver_connection_params=self._driver_connection_params,
253253
)
@@ -260,7 +260,7 @@ def export_initial_telemetry_log(self, driver_connection_params, user_agent):
260260
logger.debug("Failed to export initial telemetry log: %s", e)
261261

262262
def export_failure_log(self, error_name, error_message):
263-
logger.debug("Exporting failure log for connection %s", self._connection_uuid)
263+
logger.debug("Exporting failure log for connection %s", self._session_id_hex)
264264
try:
265265
error_info = DriverErrorInfo(
266266
error_name=error_name, stack_trace=error_message
@@ -275,7 +275,7 @@ def export_failure_log(self, error_name, error_message):
275275
),
276276
entry=FrontendLogEntry(
277277
sql_driver_log=TelemetryEvent(
278-
session_id=self._connection_uuid,
278+
session_id=self._session_id_hex,
279279
system_configuration=TelemetryHelper.get_driver_system_configuration(),
280280
driver_connection_params=self._driver_connection_params,
281281
error_info=error_info,
@@ -288,9 +288,9 @@ def export_failure_log(self, error_name, error_message):
288288

289289
def close(self):
290290
"""Flush remaining events before closing"""
291-
logger.debug("Closing TelemetryClient for connection %s", self._connection_uuid)
291+
logger.debug("Closing TelemetryClient for connection %s", self._session_id_hex)
292292
self._flush()
293-
_remove_telemetry_client(self._connection_uuid)
293+
_remove_telemetry_client(self._session_id_hex)
294294

295295

296296
# Module-level state
@@ -340,55 +340,55 @@ def _handle_unhandled_exception(exc_type, exc_value, exc_traceback):
340340

341341

342342
def initialize_telemetry_client(
343-
telemetry_enabled, connection_uuid, auth_provider, host_url
343+
telemetry_enabled, session_id_hex, auth_provider, host_url
344344
):
345345
"""Initialize a telemetry client for a specific connection if telemetry is enabled"""
346346
try:
347347
_initialize()
348348

349349
with _lock:
350-
if connection_uuid not in _clients:
350+
if session_id_hex not in _clients:
351351
logger.debug(
352-
"Creating new TelemetryClient for connection %s", connection_uuid
352+
"Creating new TelemetryClient for connection %s", session_id_hex
353353
)
354354
if telemetry_enabled:
355-
_clients[connection_uuid] = TelemetryClient(
355+
_clients[session_id_hex] = TelemetryClient(
356356
telemetry_enabled=telemetry_enabled,
357-
connection_uuid=connection_uuid,
357+
session_id_hex=session_id_hex,
358358
auth_provider=auth_provider,
359359
host_url=host_url,
360360
executor=_executor,
361361
)
362362
else:
363-
_clients[connection_uuid] = NOOP_TELEMETRY_CLIENT
363+
_clients[session_id_hex] = NOOP_TELEMETRY_CLIENT
364364
except Exception as e:
365365
logger.debug("Failed to initialize telemetry client: %s", e)
366366
# Fallback to NoopTelemetryClient to ensure connection doesn't fail
367-
_clients[connection_uuid] = NOOP_TELEMETRY_CLIENT
367+
_clients[session_id_hex] = NOOP_TELEMETRY_CLIENT
368368

369369

370-
def get_telemetry_client(connection_uuid):
370+
def get_telemetry_client(session_id_hex):
371371
"""Get the telemetry client for a specific connection"""
372372
try:
373-
if connection_uuid in _clients:
374-
return _clients[connection_uuid]
373+
if session_id_hex in _clients:
374+
return _clients[session_id_hex]
375375
else:
376376
logger.error(
377-
"Telemetry client not initialized for connection %s", connection_uuid
377+
"Telemetry client not initialized for connection %s", session_id_hex
378378
)
379379
return NOOP_TELEMETRY_CLIENT
380380
except Exception as e:
381381
logger.debug("Failed to get telemetry client: %s", e)
382382
return NOOP_TELEMETRY_CLIENT
383383

384384

385-
def _remove_telemetry_client(connection_uuid):
385+
def _remove_telemetry_client(session_id_hex):
386386
"""Remove the telemetry client for a specific connection"""
387387
global _initialized, _executor
388388
with _lock:
389-
if connection_uuid in _clients:
390-
logger.debug("Removing telemetry client for connection %s", connection_uuid)
391-
_clients.pop(connection_uuid, None)
389+
if session_id_hex in _clients:
390+
logger.debug("Removing telemetry client for connection %s", session_id_hex)
391+
_clients.pop(session_id_hex, None)
392392

393393
# Shutdown executor if no more clients
394394
if not _clients and _executor:

0 commit comments

Comments
 (0)