From 2ada230670dc9c368023cb822c9b213db65ab635 Mon Sep 17 00:00:00 2001 From: Krista Pratico Date: Mon, 19 Apr 2021 16:31:12 -0700 Subject: [PATCH] unredact headers and query params for logging (#18117) --- .../azure/ai/translation/document/_client.py | 3 ++ .../azure/ai/translation/document/_helpers.py | 37 +++++++++++++++++++ .../translation/document/aio/_client_async.py | 2 + 3 files changed, 42 insertions(+) create mode 100644 sdk/translation/azure-ai-translation-document/azure/ai/translation/document/_helpers.py diff --git a/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/_client.py b/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/_client.py index f96e0e1b8c3c..33a3abe11d98 100644 --- a/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/_client.py +++ b/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/_client.py @@ -20,6 +20,7 @@ ) from ._user_agent import USER_AGENT from ._polling import TranslationPolling +from ._helpers import get_http_logging_policy if TYPE_CHECKING: from azure.core.paging import ItemPaged @@ -62,12 +63,14 @@ def __init__(self, endpoint, credential, **kwargs): authentication_policy = AzureKeyCredentialPolicy( name=COGNITIVE_KEY_HEADER, credential=credential ) + self._client = _BatchDocumentTranslationClient( endpoint=endpoint, credential=credential, # type: ignore api_version=self._api_version, sdk_moniker=USER_AGENT, authentication_policy=authentication_policy, + http_logging_policy=get_http_logging_policy(), **kwargs ) diff --git a/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/_helpers.py b/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/_helpers.py new file mode 100644 index 000000000000..025e5f479f97 --- /dev/null +++ b/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/_helpers.py @@ -0,0 +1,37 @@ +# coding=utf-8 +# ------------------------------------ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. +# ------------------------------------ + +from azure.core.pipeline.policies import HttpLoggingPolicy + + +def get_http_logging_policy(**kwargs): + http_logging_policy = HttpLoggingPolicy(**kwargs) + http_logging_policy.allowed_header_names.update( + { + "Operation-Location", + "Content-Encoding", + "Vary", + "apim-request-id", + "X-RequestId", + "Set-Cookie", + "X-Powered-By", + "Strict-Transport-Security", + "x-content-type-options" + } + ) + http_logging_policy.allowed_query_params.update( + { + "$top", + "$skip", + "$maxpagesize", + "ids", + "statuses", + "createdDateTimeUtcStart", + "createdDateTimeUtcEnd", + "$orderBy" + } + ) + return http_logging_policy diff --git a/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/aio/_client_async.py b/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/aio/_client_async.py index ec3e7da8556d..a6bd891f7f31 100644 --- a/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/aio/_client_async.py +++ b/sdk/translation/azure-ai-translation-document/azure/ai/translation/document/aio/_client_async.py @@ -23,6 +23,7 @@ FileFormat, DocumentStatusResult ) +from .._helpers import get_http_logging_policy from .._polling import TranslationPolling COGNITIVE_KEY_HEADER = "Ocp-Apim-Subscription-Key" @@ -70,6 +71,7 @@ def __init__( api_version=self._api_version, sdk_moniker=USER_AGENT, authentication_policy=authentication_policy, + http_logging_policy=get_http_logging_policy(), **kwargs )