Skip to content

adlfs user agent #501

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

anjaliratnam-msft
Copy link

@anjaliratnam-msft anjaliratnam-msft commented Jun 23, 2025

Added adlfs to the user agent to differentiate between adlfs and azure python sdk usage.

Request headers example:
'x-ms-version': 'REDACTED'
'Accept': 'application/xml'
'User-Agent': 'adlfs/2024.12.0 azsdk-python-storage-blob/12.25.1 Python/3.13.5 (Windows-11-10.0.26100-SP0)'
'x-ms-date': 'REDACTED'
'x-ms-client-request-id': '0fbad80d-5059-11f0-9c34-000d3a6d20b2'
'Authorization': 'REDACTED'

Copy link

@kyleknap kyleknap left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I just had a couple of suggestions.

adlfs/spec.py Outdated
@@ -2055,21 +2062,26 @@ def connect_client(self):
account_url=self.fs.account_url,
credential=cred,
_location_mode=self.fs.location_mode,
user_agent=self._user_agent,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I missed that we need to set the user_agent in this class as well as in the file system class when we talked about it offline...

Given that we need to duplicate this logic across classes along with if branch statements, it is probably worth we try to consolidate client creation to module level helper function at this point. To do this, let's:

  1. Define a top-level _USER_AGENT that we can use as the constant for the adlfs user agent.
  2. Define a top-level _create_aio_blob_service_client() function that requires an account_url and optional accepts credential and location_mode. It will use _USER_AGENT as part of creating the client
  3. Define a top-level _create_aio_blob_service_client_from_connection_string() function that requires just a connection_string. It will also set _USER_AGENT as part of creating the client.

I think in making this refactor it is going to much more manageable adding the user agent in and plumb in more configurations in the future.

@@ -2045,3 +2048,15 @@ def test_open_file_x(storage: azure.storage.blob.BlobServiceClient, tmpdir):
with fs.open("data/afile", "xb") as f:
pass
assert fs.cat_file("data/afile") == b"data"


def test_user_agent(storage: azure.storage.blob.BlobServiceClient, mocker):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great if we could expand + parameterize this test case to assert user agent being set for:

  1. Both the file system and file classes
  2. Both client creation approaches i.e., using from_connection_string and using the initializer

I think this is important given the amount of branching logic when it comes to client creation so that there is coverage for the various ways clients are created in adlfs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants