Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,14 @@ def __init__(
self.overwrite: bool = kwargs.pop("user_agent_overwrite", False)
self.use_env: bool = kwargs.pop("user_agent_use_env", True)
application_id: Optional[str] = kwargs.pop("user_agent", None)
sdk_moniker: str = kwargs.pop("sdk_moniker", "core/{}".format(azcore_version))
core_version = "core/{}".format(azcore_version)
sdk_moniker: str = kwargs.pop("sdk_moniker", core_version)

if base_user_agent:
self._user_agent = base_user_agent
else:
self._user_agent = "azsdk-python-{} Python/{} ({})".format(
sdk_moniker, platform.python_version(), platform.platform()
self._user_agent = "azsdk-python-{} {} Python/{} ({})".format(
sdk_moniker, core_version, platform.python_version(), platform.platform()
Copy link
Member

Choose a reason for hiding this comment

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

Two scenarios it may impact:

  1. If the telemetry data parser uses strict schema, it may cause breakings.
  2. If user appends their ua string (by calling add_user_agent method or using env var), it may cause data loss.

Do we need to be concerned?

Copy link
Member

@kashifkhan kashifkhan Sep 26, 2023

Choose a reason for hiding this comment

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

@xiangyan99 for # 2 would the data loss be around telemetry ( or others ) who are looking for the old UA string ?

Copy link
Member

Choose a reason for hiding this comment

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

If the ua string is too long, it will be truncated.

Because we insert rather than appending here, the most end data will be truncated which could be appended by user.

Copy link
Member Author

Choose a reason for hiding this comment

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

#1 is fair, maybe we put it at the end instead. @johanste any strong opinions here?
#2 I think is on the customer, there is no size for UserAgent in the HTTP spec, if people decided to truncate and read only a specific part, this is on them. Especially here we're adding roughly 12 bytes, which is not a lot.

)

if application_id:
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/azure-core/tests/test_user_agent_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def test_user_agent_policy(http_request):
assert user_agent._user_agent == "foo"

user_agent = UserAgentPolicy(sdk_moniker="foosdk/1.0.0")
assert user_agent._user_agent.startswith("azsdk-python-foosdk/1.0.0 Python")
assert user_agent._user_agent.startswith("azsdk-python-foosdk/1.0.0 core/")

user_agent = UserAgentPolicy(base_user_agent="foo", user_agent="bar", user_agent_use_env=False)
assert user_agent._user_agent == "bar foo"
Expand Down