Skip to content

Commit 932ee0d

Browse files
committed
logging, test fixture
Signed-off-by: Sai Shree Pradhan <saishree.pradhan@databricks.com>
1 parent 37a8803 commit 932ee0d

File tree

3 files changed

+22
-37
lines changed

3 files changed

+22
-37
lines changed

src/databricks/sql/telemetry/latency_logger.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,9 @@ class TelemetryExtractor:
2222
"""
2323

2424
def __init__(self, obj):
25-
"""
26-
Initialize the extractor with an object to wrap.
27-
28-
Args:
29-
obj: The object to extract telemetry information from.
30-
"""
3125
self._obj = obj
3226

3327
def __getattr__(self, name):
34-
"""
35-
Delegate attribute access to the wrapped object.
36-
37-
Args:
38-
name (str): The name of the attribute to access.
39-
40-
Returns:
41-
The attribute value from the wrapped object.
42-
"""
4328
return getattr(self._obj, name)
4429

4530
def get_session_id_hex(self):
@@ -155,7 +140,7 @@ def get_extractor(obj):
155140
elif obj.__class__.__name__ == "ResultSet":
156141
return ResultSetExtractor(obj)
157142
else:
158-
logger.error(f"No extractor found for {obj.__class__.__name__}")
143+
logger.debug("No extractor found for %s", obj.__class__.__name__)
159144
return None
160145

161146

src/databricks/sql/telemetry/telemetry_client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,9 @@ def _telemetry_request_callback(self, future):
239239
logger.debug("Telemetry request completed successfully")
240240
else:
241241
logger.debug(
242-
"Telemetry request failed with status code: %s",
242+
"Telemetry request failed with status code: %s, response: %s",
243243
response.status_code,
244+
response.text,
244245
)
245246

246247
except Exception as e:

tests/unit/test_telemetry.py

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,6 @@
1818
)
1919

2020

21-
@pytest.fixture
22-
def telemetry_system_reset():
23-
"""Reset telemetry system state before each test."""
24-
TelemetryClientFactory._clients.clear()
25-
if TelemetryClientFactory._executor:
26-
TelemetryClientFactory._executor.shutdown(wait=True)
27-
TelemetryClientFactory._executor = None
28-
TelemetryClientFactory._initialized = False
29-
yield
30-
TelemetryClientFactory._clients.clear()
31-
if TelemetryClientFactory._executor:
32-
TelemetryClientFactory._executor.shutdown(wait=True)
33-
TelemetryClientFactory._executor = None
34-
TelemetryClientFactory._initialized = False
35-
36-
3721
@pytest.fixture
3822
def mock_telemetry_client():
3923
"""Create a mock telemetry client for testing."""
@@ -200,7 +184,22 @@ def test_auth_flow_detection(self):
200184
class TestTelemetryFactory:
201185
"""Tests for TelemetryClientFactory lifecycle and management."""
202186

203-
def test_client_lifecycle_flow(self, telemetry_system_reset):
187+
@pytest.fixture(autouse=True)
188+
def telemetry_system_reset(self):
189+
"""Reset telemetry system state before each test."""
190+
TelemetryClientFactory._clients.clear()
191+
if TelemetryClientFactory._executor:
192+
TelemetryClientFactory._executor.shutdown(wait=True)
193+
TelemetryClientFactory._executor = None
194+
TelemetryClientFactory._initialized = False
195+
yield
196+
TelemetryClientFactory._clients.clear()
197+
if TelemetryClientFactory._executor:
198+
TelemetryClientFactory._executor.shutdown(wait=True)
199+
TelemetryClientFactory._executor = None
200+
TelemetryClientFactory._initialized = False
201+
202+
def test_client_lifecycle_flow(self):
204203
"""Test complete client lifecycle: initialize -> use -> close."""
205204
session_id_hex = "test-session"
206205
auth_provider = AccessTokenAuthProvider("token")
@@ -226,7 +225,7 @@ def test_client_lifecycle_flow(self, telemetry_system_reset):
226225
client = TelemetryClientFactory.get_telemetry_client(session_id_hex)
227226
assert isinstance(client, NoopTelemetryClient)
228227

229-
def test_disabled_telemetry_flow(self, telemetry_system_reset):
228+
def test_disabled_telemetry_flow(self):
230229
"""Test that disabled telemetry uses NoopTelemetryClient."""
231230
session_id_hex = "test-session"
232231

@@ -240,7 +239,7 @@ def test_disabled_telemetry_flow(self, telemetry_system_reset):
240239
client = TelemetryClientFactory.get_telemetry_client(session_id_hex)
241240
assert isinstance(client, NoopTelemetryClient)
242241

243-
def test_factory_error_handling(self, telemetry_system_reset):
242+
def test_factory_error_handling(self):
244243
"""Test that factory errors fall back to NoopTelemetryClient."""
245244
session_id = "test-session"
246245

@@ -258,7 +257,7 @@ def test_factory_error_handling(self, telemetry_system_reset):
258257
client = TelemetryClientFactory.get_telemetry_client(session_id)
259258
assert isinstance(client, NoopTelemetryClient)
260259

261-
def test_factory_shutdown_flow(self, telemetry_system_reset):
260+
def test_factory_shutdown_flow(self):
262261
"""Test factory shutdown when last client is removed."""
263262
session1 = "session-1"
264263
session2 = "session-2"

0 commit comments

Comments
 (0)