Skip to content

Commit f89414f

Browse files
authored
[ML] Re-enable sdk logging (#26877)
* Re-enable logging with opencensus * Add tests back * Fix import and change variable names * Add pylint disable for abstract class, add logger, and fix pylint error * Add check for jupyter notebook * remove comment * Move jupyter check to get_appinsights_log_handler * Move jupyter check to get_appinsights_log_handler * Update ops_logger.update_info in code and component operations * fix circular import and pylint errors * Move in_jupyter_notebook * Update docstring * Rename logger attribute to package_logger * Update OpsHandler logger attribute to package_logger * Update README telemetry section * Refactor telemetry_collection_disabled * Fix pylint * Add test for telemetry disabling
1 parent 2c4c988 commit f89414f

23 files changed

+343
-475
lines changed

sdk/ml/azure-ai-ml/README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,11 @@ See full SDK logging documentation with examples [here][sdk_logging_docs].
9494

9595
### Telemetry
9696

97-
The Azure ML Python SDK includes a telemetry feature that collects usage and failure data about the SDK and sends it to Microsoft when you use the SDK.
97+
The Azure ML Python SDK includes a telemetry feature that collects usage and failure data about the SDK and sends it to Microsoft when you use the SDK in a Jupyter Notebook only.
98+
<u>Telemetry will **not** be collected for any use of the Python SDK outside of a Jupyter Notebook.</u>
99+
98100
Telemetry data helps the SDK team understand how the SDK is used so it can be improved and the information about failures helps the team resolve problems and fix bugs.
99-
The SDK telemetry feature is enabled by default. To opt out of the telemetry feature, set the AZUREML_SDKV2_TELEMETRY_OPTOUT environment variable to 1 or true.
101+
The SDK telemetry feature is enabled by default for Jupyter Notebook usage. To opt out of the telemetry feature, set the AZUREML_SDKV2_TELEMETRY_OPTOUT environment variable to '1' or 'true'.
100102

101103
## Next steps
102104

sdk/ml/azure-ai-ml/azure/ai/ml/_ml_client.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from azure.ai.ml._restclient.v2022_10_01_preview import AzureMachineLearningWorkspaces as ServiceClient102022Preview
3232
from azure.ai.ml._restclient.v2022_10_01 import AzureMachineLearningWorkspaces as ServiceClient102022
3333
from azure.ai.ml._scope_dependent_operations import OperationConfig, OperationsContainer, OperationScope
34+
from azure.ai.ml._telemetry.logging_handler import get_appinsights_log_handler
3435
from azure.ai.ml._user_agent import USER_AGENT
3536
from azure.ai.ml._utils._experimental import experimental
3637
from azure.ai.ml._utils._http_utils import HttpPipeline
@@ -215,12 +216,12 @@ def __init__(
215216
if registry_name:
216217
properties.update({"registry_name": registry_name})
217218

218-
# user_agent = None
219-
# if "user_agent" in kwargs:
220-
# user_agent = kwargs.get("user_agent")
221-
# app_insights_handler = get_appinsights_log_handler(user_agent, **{"properties": properties})
222-
# app_insights_handler_kwargs = {"app_insights_handler": app_insights_handler}
223-
app_insights_handler_kwargs = {}
219+
user_agent = None
220+
if "user_agent" in kwargs:
221+
user_agent = kwargs.get("user_agent")
222+
223+
app_insights_handler = get_appinsights_log_handler(user_agent, **{"properties": properties})
224+
app_insights_handler_kwargs = {"app_insights_handler": app_insights_handler}
224225

225226
base_url = _get_base_url_from_metadata(cloud_name=cloud_name, is_local_mfe=True)
226227
self._base_url = base_url

sdk/ml/azure-ai-ml/azure/ai/ml/_telemetry/__init__.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

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

7-
# from .activity import ActivityType, log_activity, monitor_with_activity, monitor_with_telemetry_mixin
8-
# from .logging_handler import AML_INTERNAL_LOGGER_NAMESPACE, get_appinsights_log_handler
7+
from .activity import ActivityType, log_activity, monitor_with_activity, monitor_with_telemetry_mixin
8+
from .logging_handler import AML_INTERNAL_LOGGER_NAMESPACE, get_appinsights_log_handler
99

1010
__all__ = [
11-
# "monitor_with_activity",
12-
# "monitor_with_telemetry_mixin",
13-
# "log_activity",
14-
# "ActivityType",
15-
# "get_appinsights_log_handler",
16-
# "AML_INTERNAL_LOGGER_NAMESPACE",
11+
"monitor_with_activity",
12+
"monitor_with_telemetry_mixin",
13+
"log_activity",
14+
"ActivityType",
15+
"get_appinsights_log_handler",
16+
"AML_INTERNAL_LOGGER_NAMESPACE",
1717
]

sdk/ml/azure-ai-ml/azure/ai/ml/_telemetry/activity.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222

2323
from marshmallow import ValidationError
2424

25-
from azure.ai.ml.exceptions import ErrorCategory, MlException
2625
from azure.core.exceptions import HttpResponseError
2726

28-
from .._utils.utils import _is_user_error_from_exception_type, _is_user_error_from_status_code, _str_to_bool
27+
from azure.ai.ml._utils.utils import _is_user_error_from_exception_type, _is_user_error_from_status_code, _str_to_bool
28+
from azure.ai.ml.exceptions import ErrorCategory, MlException
2929

3030
# Get environment variable IS_IN_CI_PIPELINE to decide whether it's in CI test
3131
IS_IN_CI_PIPELINE = _str_to_bool(os.environ.get("IS_IN_CI_PIPELINE", "False"))

0 commit comments

Comments
 (0)