File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -402,8 +402,12 @@ def read(self) -> Optional[OAuthToken]:
402402 )
403403 self .session .open ()
404404 except Exception as e :
405- # Respect user's telemetry preference even during connection failure
406- enable_telemetry = kwargs .get ("enable_telemetry" , True )
405+ # Respect user's telemetry preference even during connection failure.
406+ # For use_kernel connections the kernel owns telemetry, so suppress
407+ # the wrapper-side failure log to avoid wrapper-vs-kernel duplication.
408+ enable_telemetry = kwargs .get ("enable_telemetry" , True ) and not kwargs .get (
409+ "use_kernel" , False
410+ )
407411 TelemetryClientFactory .connection_failure_log (
408412 error_name = "Exception" ,
409413 error_message = str (e ),
Original file line number Diff line number Diff line change @@ -488,6 +488,36 @@ def test_connection_failure_sends_correct_telemetry_payload(
488488 assert call_arguments [0 ][0 ] == "Exception"
489489 assert call_arguments [0 ][1 ] == error_message
490490
491+ @patch (
492+ "databricks.sql.telemetry.telemetry_client.TelemetryClient.export_failure_log"
493+ )
494+ @patch ("databricks.sql.client.Session" )
495+ def test_connection_failure_does_not_send_telemetry_for_kernel (
496+ self , mock_session , mock_export_failure_log
497+ ):
498+ """
499+ A use_kernel=True connection that fails to open must NOT emit a
500+ wrapper-side failure log — the kernel owns telemetry, so emitting
501+ here would duplicate the kernel's own failure reporting.
502+ """
503+
504+ error_message = "Could not connect to host"
505+ mock_session_instance = MagicMock ()
506+ mock_session_instance .is_open = False
507+ mock_session_instance .open .side_effect = Exception (error_message )
508+ mock_session .return_value = mock_session_instance
509+
510+ try :
511+ sql .connect (
512+ server_hostname = "test-host" ,
513+ http_path = "/test-path" ,
514+ use_kernel = True ,
515+ )
516+ except Exception as e :
517+ assert str (e ) == error_message
518+
519+ mock_export_failure_log .assert_not_called ()
520+
491521
492522@patch ("databricks.sql.client.Session" )
493523class TestTelemetryFeatureFlag :
You can’t perform that action at this time.
0 commit comments