diff --git a/databricks/sdk/dbutils.py b/databricks/sdk/dbutils.py index af5ebb821..6deffc0fc 100644 --- a/databricks/sdk/dbutils.py +++ b/databricks/sdk/dbutils.py @@ -210,7 +210,11 @@ def __init__(self) -> None: class RemoteDbUtils: def __init__(self, config: "Config" = None): - self._config = Config() if not config else config + # Create a shallow copy of the config to allow the use of a custom + # user-agent while avoiding modifying the original config. + self._config = Config() if not config else config.copy() + self._config.with_user_agent_extra("dbutils", "remote") + self._client = ApiClient(self._config) self._clusters = compute_ext.ClustersExt(self._client) self._commands = compute.CommandExecutionAPI(self._client) diff --git a/tests/test_dbutils.py b/tests/test_dbutils.py index 9cd3d32fd..638e7e9b2 100644 --- a/tests/test_dbutils.py +++ b/tests/test_dbutils.py @@ -290,3 +290,12 @@ def test_dbutils_proxy_overrides(dbutils, mocker, restorable_env): return_value="test_cluster_id", ) assert dbutils.notebook.entry_point.getDbutils().notebook().getContext().notebookPath().get() == "test_source_file" + + +def test_dbutils_adds_user_agent(config): + from databricks.sdk.dbutils import RemoteDbUtils + + # Create dbutils and check that user-agent includes sdk-feature/dbutils + dbutils = RemoteDbUtils(config) + + assert "dbutils/remote" in dbutils._config.user_agent