Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 142b9a8

Browse files
committed
added _safe_call which returns None in case of errors in the get functions
Signed-off-by: Sai Shree Pradhan <[email protected]>
1 parent e031663 commit 142b9a8

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/databricks/sql/telemetry/latency_logger.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,18 +195,26 @@ def wrapper(self, *args, **kwargs):
195195
result = func(self, *args, **kwargs)
196196
return result
197197
finally:
198+
199+
def _safe_call(func_to_call):
200+
"""Calls a function and returns a default value on any exception."""
201+
try:
202+
return func_to_call()
203+
except Exception:
204+
return None
205+
198206
end_time = time.perf_counter()
199207
duration_ms = int((end_time - start_time) * 1000)
200208

201209
extractor = get_extractor(self)
202-
session_id_hex = extractor.get_session_id_hex()
203-
statement_id = extractor.get_statement_id()
210+
session_id_hex = _safe_call(extractor.get_session_id_hex)
211+
statement_id = _safe_call(extractor.get_statement_id)
204212

205213
sql_exec_event = SqlExecutionEvent(
206214
statement_type=statement_type,
207-
is_compressed=extractor.get_is_compressed(),
208-
execution_result=extractor.get_execution_result(),
209-
retry_count=extractor.get_retry_count(),
215+
is_compressed=_safe_call(extractor.get_is_compressed),
216+
execution_result=_safe_call(extractor.get_execution_result),
217+
retry_count=_safe_call(extractor.get_retry_count),
210218
)
211219

212220
telemetry_client = TelemetryClientFactory.get_telemetry_client(

0 commit comments

Comments
 (0)