Skip to content

Commit 21f8ff7

Browse files
Add dbutils/remote to the user agent of calls made through the RemoteDbUtils client. (#1070)
## What changes are proposed in this pull request? Simple PR adding `dbutils/remote` to the user agent of calls made through the `RemoteDbUtils` client. ## How is this tested? Unit + Integration tests. NO_CHANGELOG=true
1 parent 946de3e commit 21f8ff7

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

databricks/sdk/dbutils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,11 @@ def __init__(self) -> None:
210210
class RemoteDbUtils:
211211

212212
def __init__(self, config: "Config" = None):
213-
self._config = Config() if not config else config
213+
# Create a shallow copy of the config to allow the use of a custom
214+
# user-agent while avoiding modifying the original config.
215+
self._config = Config() if not config else config.copy()
216+
self._config.with_user_agent_extra("dbutils", "remote")
217+
214218
self._client = ApiClient(self._config)
215219
self._clusters = compute_ext.ClustersExt(self._client)
216220
self._commands = compute.CommandExecutionAPI(self._client)

tests/test_dbutils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,3 +290,12 @@ def test_dbutils_proxy_overrides(dbutils, mocker, restorable_env):
290290
return_value="test_cluster_id",
291291
)
292292
assert dbutils.notebook.entry_point.getDbutils().notebook().getContext().notebookPath().get() == "test_source_file"
293+
294+
295+
def test_dbutils_adds_user_agent(config):
296+
from databricks.sdk.dbutils import RemoteDbUtils
297+
298+
# Create dbutils and check that user-agent includes sdk-feature/dbutils
299+
dbutils = RemoteDbUtils(config)
300+
301+
assert "dbutils/remote" in dbutils._config.user_agent

0 commit comments

Comments
 (0)