Skip to content
Open
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
2 changes: 1 addition & 1 deletion sdk/ai/azure-ai-projects/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "python",
"TagPrefix": "python/ai/azure-ai-projects",
"Tag": "python/ai/azure-ai-projects_b0e6f379ee"
"Tag": "python/ai/azure-ai-projects_838ee29bca"
}
8 changes: 8 additions & 0 deletions sdk/ai/azure-ai-projects/azure/ai/projects/_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from azure.identity import get_bearer_token_provider
from ._client import AIProjectClient as AIProjectClientGenerated
from .operations import TelemetryOperations
from ._version import VERSION


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -141,6 +142,11 @@ def get_openai_client(self, **kwargs: Any) -> "OpenAI": # type: ignore[name-def
base_url,
)

default_headers = kwargs.get("default_headers", {})
user_agent = default_headers.get("User-Agent", "")
default_headers["User-Agent"] = ", ".join([str(user_agent), f"AzureAIProjects/{VERSION}"]).lstrip(", ")
kwargs["default_headers"] = default_headers

http_client = None

if self._console_logging_enabled:
Expand Down Expand Up @@ -179,6 +185,8 @@ def handle_request(self, request: httpx.Request) -> httpx.Response:

print(f"\n==> Request:\n{request.method} {request.url}")
headers = dict(request.headers)
if "user-agent" in headers:
headers["user-agent"] += f", AzureAIProjects/{VERSION}"
self._sanitize_auth_header(headers)
print("Headers:")
for key, value in sorted(headers.items()):
Expand Down
5 changes: 5 additions & 0 deletions sdk/ai/azure-ai-projects/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
add_body_key_sanitizer,
add_remove_header_sanitizer,
add_body_regex_sanitizer,
add_header_regex_sanitizer,
)

if not load_dotenv(find_dotenv(), override=True):
print("Did not find a .env file. Using default environment variable values for tests.")


def pytest_collection_modifyitems(items):
if os.environ.get("AZURE_TEST_RUN_LIVE") == "true":
return
Expand Down Expand Up @@ -157,6 +159,9 @@ def sanitize_url_paths():
headers="x-stainless-arch, x-stainless-async, x-stainless-lang, x-stainless-os, x-stainless-package-version, x-stainless-read-timeout, x-stainless-retry-count, x-stainless-runtime, x-stainless-runtime-version"
)

# Sanitize User-Agent header to avoid platform-specific information in recordings
add_header_regex_sanitizer(key="User-Agent", value="sanitized-user-agent")

# Remove the following sanitizers since certain fields are needed in tests and are non-sensitive:
# - AZSDK3493: $..name
# - AZSDK3430: $..id
Expand Down
Loading