Skip to content

Commit

Permalink
[ML] Disable sdk telemetry logging (Azure#27603)
Browse files Browse the repository at this point in the history
* Disable sdk telemetry logging
  • Loading branch information
diondrapeck authored and nthandeMS committed Nov 18, 2022
1 parent 1b225fc commit 9295e4b
Show file tree
Hide file tree
Showing 20 changed files with 281 additions and 279 deletions.
13 changes: 7 additions & 6 deletions sdk/ml/azure-ai-ml/azure/ai/ml/_ml_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from azure.ai.ml._restclient.v2022_10_01_preview import AzureMachineLearningWorkspaces as ServiceClient102022Preview
from azure.ai.ml._restclient.v2022_10_01 import AzureMachineLearningWorkspaces as ServiceClient102022
from azure.ai.ml._scope_dependent_operations import OperationConfig, OperationsContainer, OperationScope
from azure.ai.ml._telemetry.logging_handler import get_appinsights_log_handler
#from azure.ai.ml._telemetry.logging_handler import get_appinsights_log_handler
from azure.ai.ml._user_agent import USER_AGENT
from azure.ai.ml._utils._experimental import experimental
from azure.ai.ml._utils._http_utils import HttpPipeline
Expand Down Expand Up @@ -216,12 +216,13 @@ def __init__(
if registry_name:
properties.update({"registry_name": registry_name})

user_agent = None
if "user_agent" in kwargs:
user_agent = kwargs.get("user_agent")
# user_agent = None
# if "user_agent" in kwargs:
# user_agent = kwargs.get("user_agent")

app_insights_handler = get_appinsights_log_handler(user_agent, **{"properties": properties})
app_insights_handler_kwargs = {"app_insights_handler": app_insights_handler}
# app_insights_handler = get_appinsights_log_handler(user_agent, **{"properties": properties})
# app_insights_handler_kwargs = {"app_insights_handler": app_insights_handler}
app_insights_handler_kwargs = {}

base_url = _get_base_url_from_metadata(cloud_name=cloud_name, is_local_mfe=True)
self._base_url = base_url
Expand Down
16 changes: 8 additions & 8 deletions sdk/ml/azure-ai-ml/azure/ai/ml/_telemetry/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

__path__ = __import__("pkgutil").extend_path(__path__, __name__)

from .activity import ActivityType, log_activity, monitor_with_activity, monitor_with_telemetry_mixin
from .logging_handler import AML_INTERNAL_LOGGER_NAMESPACE, get_appinsights_log_handler
# from .activity import ActivityType, log_activity, monitor_with_activity, monitor_with_telemetry_mixin
# from .logging_handler import AML_INTERNAL_LOGGER_NAMESPACE, get_appinsights_log_handler

__all__ = [
"monitor_with_activity",
"monitor_with_telemetry_mixin",
"log_activity",
"ActivityType",
"get_appinsights_log_handler",
"AML_INTERNAL_LOGGER_NAMESPACE",
# "monitor_with_activity",
# "monitor_with_telemetry_mixin",
# "log_activity",
# "ActivityType",
# "get_appinsights_log_handler",
# "AML_INTERNAL_LOGGER_NAMESPACE",
]
112 changes: 56 additions & 56 deletions sdk/ml/azure-ai-ml/azure/ai/ml/_telemetry/logging_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
"""Contains functionality for sending telemetry to Application Insights via OpenCensus Azure Monitor Exporter."""

import logging
import platform
# import platform
from os import getenv

from opencensus.ext.azure.log_exporter import AzureLogHandler
# from opencensus.ext.azure.log_exporter import AzureLogHandler

from azure.ai.ml._user_agent import USER_AGENT
# from azure.ai.ml._user_agent import USER_AGENT


AML_INTERNAL_LOGGER_NAMESPACE = "azure.ai.ml._telemetry"
Expand Down Expand Up @@ -86,56 +86,56 @@ def is_telemetry_collection_disabled():
return False


def get_appinsights_log_handler(
user_agent,
*args, # pylint: disable=unused-argument
instrumentation_key=None,
component_name=None,
**kwargs
):
"""Enable the OpenCensus logging handler for specified logger and instrumentation key to send info to AppInsights.
:param user_agent: Information about the user's browser.
:type user_agent: Dict[str, str]
:param instrumentation_key: The Application Insights instrumentation key.
:type instrumentation_key: str
:param component_name: The component name.
:type component_name: str
:param args: Optional arguments for formatting messages.
:type args: list
:param kwargs: Optional keyword arguments for adding additional information to messages.
:type kwargs: dict
:return: The logging handler.
:rtype: opencensus.ext.azure.log_exporter.AzureLogHandler
"""
try:
if instrumentation_key is None:
instrumentation_key = INSTRUMENTATION_KEY

if is_telemetry_collection_disabled():
return logging.NullHandler()

if not user_agent or not user_agent.lower() == USER_AGENT.lower():
return logging.NullHandler()

if "properties" in kwargs and "subscription_id" in kwargs.get("properties"):
if kwargs.get("properties")["subscription_id"] in test_subscriptions:
return logging.NullHandler()

child_namespace = component_name or __name__
current_logger = logging.getLogger(AML_INTERNAL_LOGGER_NAMESPACE).getChild(child_namespace)
current_logger.propagate = False
current_logger.setLevel(logging.CRITICAL)

custom_properties = {"PythonVersion": platform.python_version()}
custom_properties.update({"user_agent": user_agent})
if "properties" in kwargs:
custom_properties.update(kwargs.pop("properties"))
handler = AzureLogHandler(connection_string=f'InstrumentationKey={instrumentation_key}')
current_logger.addHandler(handler)
handler.addFilter(CustomDimensionsFilter(custom_properties))

return handler
except Exception: # pylint: disable=broad-except
# ignore exceptions, telemetry should not block
return logging.NullHandler()
# def get_appinsights_log_handler(
# user_agent,
# *args, # pylint: disable=unused-argument
# instrumentation_key=None,
# component_name=None,
# **kwargs
# ):
# """Enable the OpenCensus logging handler for specified logger and instrumentation key to send info to AppInsights.

# :param user_agent: Information about the user's browser.
# :type user_agent: Dict[str, str]
# :param instrumentation_key: The Application Insights instrumentation key.
# :type instrumentation_key: str
# :param component_name: The component name.
# :type component_name: str
# :param args: Optional arguments for formatting messages.
# :type args: list
# :param kwargs: Optional keyword arguments for adding additional information to messages.
# :type kwargs: dict
# :return: The logging handler.
# :rtype: opencensus.ext.azure.log_exporter.AzureLogHandler
# """
# try:
# if instrumentation_key is None:
# instrumentation_key = INSTRUMENTATION_KEY

# if is_telemetry_collection_disabled():
# return logging.NullHandler()

# if not user_agent or not user_agent.lower() == USER_AGENT.lower():
# return logging.NullHandler()

# if "properties" in kwargs and "subscription_id" in kwargs.get("properties"):
# if kwargs.get("properties")["subscription_id"] in test_subscriptions:
# return logging.NullHandler()

# child_namespace = component_name or __name__
# current_logger = logging.getLogger(AML_INTERNAL_LOGGER_NAMESPACE).getChild(child_namespace)
# current_logger.propagate = False
# current_logger.setLevel(logging.CRITICAL)

# custom_properties = {"PythonVersion": platform.python_version()}
# custom_properties.update({"user_agent": user_agent})
# if "properties" in kwargs:
# custom_properties.update(kwargs.pop("properties"))
# handler = AzureLogHandler(connection_string=f'InstrumentationKey={instrumentation_key}')
# current_logger.addHandler(handler)
# handler.addFilter(CustomDimensionsFilter(custom_properties))

# return handler
# except Exception: # pylint: disable=broad-except
# # ignore exceptions, telemetry should not block
# return logging.NullHandler()
12 changes: 6 additions & 6 deletions sdk/ml/azure-ai-ml/azure/ai/ml/_utils/_logger_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import logging
import sys

from azure.ai.ml._telemetry.logging_handler import AML_INTERNAL_LOGGER_NAMESPACE
# from azure.ai.ml._telemetry.logging_handler import AML_INTERNAL_LOGGER_NAMESPACE


def initialize_logger_info(module_logger: logging.Logger, terminator="\n") -> None:
Expand All @@ -20,11 +20,11 @@ def initialize_logger_info(module_logger: logging.Logger, terminator="\n") -> No

class OpsLogger:
def __init__(self, name: str):
self.package_logger: logging.Logger = logging.getLogger(AML_INTERNAL_LOGGER_NAMESPACE + name)
self.package_logger.propagate = False
# self.package_logger: logging.Logger = logging.getLogger(AML_INTERNAL_LOGGER_NAMESPACE + name)
# self.package_logger.propagate = False
self.module_logger = logging.getLogger(name)
self.custom_dimensions = {}

def update_info(self, data: dict) -> None:
if "app_insights_handler" in data:
self.package_logger.addHandler(data.pop("app_insights_handler"))
# def update_info(self, data: dict) -> None:
# if "app_insights_handler" in data:
# self.package_logger.addHandler(data.pop("app_insights_handler"))
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
OperationScope,
_ScopeDependentOperations,
)
from azure.ai.ml._telemetry import ActivityType, monitor_with_activity
# from azure.ai.ml._telemetry import ActivityType, monitor_with_activity
from azure.ai.ml._utils._azureml_polling import AzureMLPolling
from azure.ai.ml._utils._arm_id_utils import AMLVersionedArmId
from azure.ai.ml._utils._endpoint_utils import upload_dependencies, validate_scoring_script
Expand All @@ -31,7 +31,7 @@
from ._operation_orchestrator import OperationOrchestrator

ops_logger = OpsLogger(__name__)
logger, module_logger = ops_logger.package_logger, ops_logger.module_logger
module_logger = ops_logger.module_logger


class BatchDeploymentOperations(_ScopeDependentOperations):
Expand All @@ -52,7 +52,7 @@ def __init__(
**kwargs: Dict,
):
super(BatchDeploymentOperations, self).__init__(operation_scope, operation_config)
ops_logger.update_info(kwargs)
# ops_logger.update_info(kwargs)
self._batch_deployment = service_client_05_2022.batch_deployments
self._batch_job_deployment = kwargs.pop("service_client_09_2020_dataplanepreview").batch_job_deployment
self._batch_endpoint_operations = service_client_05_2022.batch_endpoints
Expand All @@ -63,7 +63,7 @@ def __init__(
self._requests_pipeline: HttpPipeline = kwargs.pop("requests_pipeline")

@distributed_trace
@monitor_with_activity(logger, "BatchDeployment.BeginCreateOrUpdate", ActivityType.PUBLICAPI)
# @monitor_with_activity(logger, "BatchDeployment.BeginCreateOrUpdate", ActivityType.PUBLICAPI)
def begin_create_or_update(
self,
deployment: BatchDeployment,
Expand Down Expand Up @@ -126,7 +126,7 @@ def begin_create_or_update(
raise ex

@distributed_trace
@monitor_with_activity(logger, "BatchDeployment.Get", ActivityType.PUBLICAPI)
# @monitor_with_activity(logger, "BatchDeployment.Get", ActivityType.PUBLICAPI)
def get(self, name: str, endpoint_name: str) -> BatchDeployment:
"""Get a deployment resource.
Expand All @@ -151,7 +151,7 @@ def get(self, name: str, endpoint_name: str) -> BatchDeployment:
return deployment

@distributed_trace
@monitor_with_activity(logger, "BatchDeployment.BeginDelete", ActivityType.PUBLICAPI)
# @monitor_with_activity(logger, "BatchDeployment.BeginDelete", ActivityType.PUBLICAPI)
def begin_delete(self, name: str, endpoint_name: str) -> LROPoller[None]:
"""Delete a batch deployment.
Expand Down Expand Up @@ -184,7 +184,7 @@ def begin_delete(self, name: str, endpoint_name: str) -> LROPoller[None]:
return delete_poller

@distributed_trace
@monitor_with_activity(logger, "BatchDeployment.List", ActivityType.PUBLICAPI)
# @monitor_with_activity(logger, "BatchDeployment.List", ActivityType.PUBLICAPI)
def list(self, endpoint_name: str) -> ItemPaged[BatchDeployment]:
"""List a deployment resource.
Expand All @@ -202,7 +202,7 @@ def list(self, endpoint_name: str) -> ItemPaged[BatchDeployment]:
)

@distributed_trace
@monitor_with_activity(logger, "BatchDeployment.ListJobs", ActivityType.PUBLICAPI)
# @monitor_with_activity(logger, "BatchDeployment.ListJobs", ActivityType.PUBLICAPI)
def list_jobs(self, endpoint_name: str, *, name: str = None) -> ItemPaged[BatchJob]:
"""List jobs under the provided batch endpoint deployment. This is only
valid for batch endpoint.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
OperationScope,
_ScopeDependentOperations,
)
from azure.ai.ml._telemetry import ActivityType, monitor_with_activity
# from azure.ai.ml._telemetry import ActivityType, monitor_with_activity
from azure.ai.ml._utils._arm_id_utils import get_datastore_arm_id, is_ARM_id_for_resource, remove_datastore_prefix
from azure.ai.ml._utils._azureml_polling import AzureMLPolling
from azure.ai.ml._utils._endpoint_utils import validate_response
Expand Down Expand Up @@ -55,7 +55,7 @@
from azure.ai.ml.operations import DatastoreOperations

ops_logger = OpsLogger(__name__)
logger, module_logger = ops_logger.package_logger, ops_logger.module_logger
module_logger = ops_logger.module_logger


class BatchEndpointOperations(_ScopeDependentOperations):
Expand All @@ -77,7 +77,7 @@ def __init__(
):

super(BatchEndpointOperations, self).__init__(operation_scope, operation_config)
ops_logger.update_info(kwargs)
# ops_logger.update_info(kwargs)
self._batch_operation = service_client_05_2022.batch_endpoints
self._batch_deployment_operation = service_client_05_2022.batch_deployments
self._batch_job_endpoint = kwargs.pop("service_client_09_2020_dataplanepreview").batch_job_endpoint
Expand All @@ -92,7 +92,7 @@ def _datastore_operations(self) -> "DatastoreOperations":
return self._all_operations.all_operations[AzureMLResourceType.DATASTORE]

@distributed_trace
@monitor_with_activity(logger, "BatchEndpoint.List", ActivityType.PUBLICAPI)
# @monitor_with_activity(logger, "BatchEndpoint.List", ActivityType.PUBLICAPI)
def list(self) -> ItemPaged[BatchEndpoint]:
"""List endpoints of the workspace.
Expand All @@ -107,7 +107,7 @@ def list(self) -> ItemPaged[BatchEndpoint]:
)

@distributed_trace
@monitor_with_activity(logger, "BatchEndpoint.Get", ActivityType.PUBLICAPI)
# @monitor_with_activity(logger, "BatchEndpoint.Get", ActivityType.PUBLICAPI)
def get(
self,
name: str,
Expand All @@ -130,7 +130,7 @@ def get(
return endpoint_data

@distributed_trace
@monitor_with_activity(logger, "BatchEndpoint.BeginDelete", ActivityType.PUBLICAPI)
# @monitor_with_activity(logger, "BatchEndpoint.BeginDelete", ActivityType.PUBLICAPI)
def begin_delete(self, name: str) -> LROPoller[None]:
"""Delete a batch Endpoint.
Expand Down Expand Up @@ -160,7 +160,7 @@ def begin_delete(self, name: str) -> LROPoller[None]:
return delete_poller

@distributed_trace
@monitor_with_activity(logger, "BatchEndpoint.BeginCreateOrUpdate", ActivityType.PUBLICAPI)
# @monitor_with_activity(logger, "BatchEndpoint.BeginCreateOrUpdate", ActivityType.PUBLICAPI)
def begin_create_or_update(self, endpoint: BatchEndpoint) -> LROPoller[BatchEndpoint]:
"""Create or update a batch endpoint.
Expand Down Expand Up @@ -188,7 +188,7 @@ def begin_create_or_update(self, endpoint: BatchEndpoint) -> LROPoller[BatchEndp
raise ex

@distributed_trace
@monitor_with_activity(logger, "BatchEndpoint.Invoke", ActivityType.PUBLICAPI)
# @monitor_with_activity(logger, "BatchEndpoint.Invoke", ActivityType.PUBLICAPI)
def invoke(
self,
endpoint_name: str,
Expand Down Expand Up @@ -294,7 +294,7 @@ def invoke(
return BatchJobResource.deserialize(batch_job)

@distributed_trace
@monitor_with_activity(logger, "BatchEndpoint.ListJobs", ActivityType.PUBLICAPI)
# @monitor_with_activity(logger, "BatchEndpoint.ListJobs", ActivityType.PUBLICAPI)
def list_jobs(self, endpoint_name: str) -> ItemPaged[BatchJob]:
"""List jobs under the provided batch endpoint deployment. This is only
valid for batch endpoint.
Expand Down
10 changes: 5 additions & 5 deletions sdk/ml/azure-ai-ml/azure/ai/ml/operations/_code_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
)
from azure.ai.ml._restclient.v2022_10_01_preview import AzureMachineLearningWorkspaces as ServiceClient102022
from azure.ai.ml._scope_dependent_operations import OperationConfig, OperationScope, _ScopeDependentOperations
from azure.ai.ml._telemetry import ActivityType, monitor_with_activity
# from azure.ai.ml._telemetry import ActivityType, monitor_with_activity
from azure.ai.ml._utils._logger_utils import OpsLogger
from azure.ai.ml._utils._registry_utils import get_asset_body_for_registry_storage, get_sas_uri_for_registry_asset
from azure.ai.ml.entities._assets import Code
Expand All @@ -35,7 +35,7 @@
from azure.core.exceptions import HttpResponseError

ops_logger = OpsLogger(__name__)
logger, module_logger = ops_logger.package_logger, ops_logger.module_logger
module_logger = ops_logger.module_logger


class CodeOperations(_ScopeDependentOperations):
Expand All @@ -54,14 +54,14 @@ def __init__(
**kwargs: Dict,
):
super(CodeOperations, self).__init__(operation_scope, operation_config)
ops_logger.update_info(kwargs)
# ops_logger.update_info(kwargs)
self._service_client = service_client
self._version_operation = service_client.code_versions
self._container_operation = service_client.code_containers
self._datastore_operation = datastore_operations
self._init_kwargs = kwargs

@monitor_with_activity(logger, "Code.CreateOrUpdate", ActivityType.PUBLICAPI)
# @monitor_with_activity(logger, "Code.CreateOrUpdate", ActivityType.PUBLICAPI)
def create_or_update(self, code: Code) -> Code:
"""Returns created or updated code asset.
Expand Down Expand Up @@ -140,7 +140,7 @@ def create_or_update(self, code: Code) -> Code:
)
raise ex

@monitor_with_activity(logger, "Code.Get", ActivityType.PUBLICAPI)
# @monitor_with_activity(logger, "Code.Get", ActivityType.PUBLICAPI)
def get(self, name: str, version: str) -> Code:
"""Returns information about the specified code asset.
Expand Down
Loading

0 comments on commit 9295e4b

Please sign in to comment.