{"id":6318,"library":"azureml-telemetry","title":"Azure ML Telemetry","description":"The `azureml-telemetry` package, currently at version 1.62.0, is a core component within the Azure Machine Learning Python SDK. It is primarily used to collect various telemetry data, including log messages, metrics, events, and activity messages, generated by Azure Machine Learning processes. This data is often routed to Azure Application Insights for monitoring and analysis. The package underpins the telemetry collection mechanisms used by other Azure ML SDK components, rather than providing a direct-use client API for end-users to send custom telemetry. Microsoft is actively transitioning towards OpenTelemetry for broader Azure Monitor integration.","status":"active","version":"1.62.0","language":"en","source_language":"en","source_url":"https://pypi.org/project/azureml-telemetry/","tags":["azure","machine learning","telemetry","logging","metrics","application insights","mlops"],"install":[{"cmd":"pip install azureml-telemetry","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"note":"The `azureml-telemetry` package itself is typically an underlying dependency; direct logging is usually performed via `azureml.core.Run` (SDK v1, deprecated) or MLflow (SDK v2, recommended).","wrong":"import azureml.telemetry as telemetry_client","symbol":"Run","correct":"from azureml.core import Run"},{"note":"For Azure Machine Learning SDK v2, MLflow is the recommended approach for logging metrics, parameters, and artifacts within experiments, which leverages underlying telemetry mechanisms.","symbol":"mlflow","correct":"import mlflow"}],"quickstart":{"code":"import os\nimport mlflow\nfrom azure.ai.ml import MLClient\nfrom azure.identity import DefaultAzureCredential\n\n# NOTE: This quickstart assumes you have an Azure Machine Learning workspace configured.\n# Replace with your actual subscription, resource group, and workspace name.\n# Set these environment variables or replace directly in the code for actual execution.\nsubscription_id = os.environ.get('AZURE_SUBSCRIPTION_ID', 'your-subscription-id')\nresource_group = os.environ.get('AZURE_RESOURCE_GROUP', 'your-resource-group')\nworkspace_name = os.environ.get('AZURE_ML_WORKSPACE_NAME', 'your-ml-workspace')\n\n# Authenticate and get MLClient\ntry:\n    ml_client = MLClient(\n        DefaultAzureCredential(), subscription_id, resource_group, workspace_name\n    )\n    print(f\"Connected to Azure ML workspace: {ml_client.workspace_name}\")\nexcept Exception as e:\n    print(f\"Could not connect to Azure ML workspace. Please ensure your credentials and workspace details are correct: {e}\")\n    print(\"Skipping MLflow example as workspace connection failed.\")\n    exit()\n\n# Set the MLflow tracking URI to point to the Azure Machine Learning backend\n# This ensures metrics and artifacts are logged to your workspace.\nmlflow.set_tracking_uri(ml_client.workspaces.get(name=workspace_name).mlflow_tracking_uri)\n\n# Start an MLflow run to log custom metrics\nwith mlflow.start_run() as run:\n    print(f\"MLflow run ID: {run.info.run_id}\")\n    # Log a simple custom metric\n    mlflow.log_metric(\"custom_accuracy\", 0.95)\n    mlflow.log_metric(\"custom_loss\", 0.05)\n    print(\"Logged custom_accuracy and custom_loss metrics.\")\n\n    # Log a parameter\n    mlflow.log_param(\"model_type\", \"linear_regression\")\n    print(\"Logged model_type parameter.\")\n\n    # Simulate a loop and log multiple metric values\n    for i in range(5):\n        mlflow.log_metric(\"iteration_accuracy\", 0.95 + i * 0.001, step=i)\n    print(\"Logged iteration_accuracy over steps.\")\n\nprint(\"Telemetry logged successfully via MLflow to Azure ML.\")\n","lang":"python","description":"This quickstart demonstrates how to log custom metrics and parameters to an Azure Machine Learning workspace using MLflow, which is the recommended approach for Azure Machine Learning SDK v2. The `azureml-telemetry` package works beneath the surface to facilitate this data collection."},"warnings":[{"fix":"Transition to Azure Machine Learning SDK v2 and use `mlflow` for logging metrics, parameters, and artifacts. Install `mlflow` and `azureml-mlflow` (`pip install mlflow azureml-mlflow`) and configure MLflow tracking to your Azure ML workspace.","message":"Azure Machine Learning SDK v1 (which uses `azureml.core.Run` for direct logging) is deprecated as of March 31, 2025, with support ending on June 30, 2026. Users are strongly recommended to migrate to Azure Machine Learning SDK v2 and leverage MLflow for experiment tracking and telemetry logging.","severity":"deprecated","affected_versions":"<=1.56.0 (SDK v1)"},{"fix":"Ensure your development and deployment environments use Python 3.9 or newer to maintain compatibility with the evolving Azure Machine Learning SDK ecosystem.","message":"While `azureml-telemetry` officially supports Python >=3.7, newer versions of related Azure ML SDKs (like `azure-ai-ml` and `azureml-core`) have deprecated support for Python 3.7 and 3.8. Relying on older Python versions within the broader Azure ML ecosystem may lead to compatibility issues or lack of support in the future.","severity":"gotcha","affected_versions":"All versions on Python <3.9"},{"fix":"For new applications or when seeking more granular control over telemetry, consider directly adopting the Azure Monitor OpenTelemetry Distro. This is a significant architectural shift that may require code changes for direct OpenTelemetry API usage, though `azureml-telemetry`'s underlying functionality may adapt.","message":"Microsoft is actively migrating towards OpenTelemetry as the recommended standard for instrumenting applications for Azure Monitor. While `azureml-telemetry` continues to function, future enhancements and direct control over telemetry might increasingly rely on `azure-monitor-opentelemetry-exporter` and the OpenTelemetry standard.","severity":"breaking","affected_versions":"All versions"},{"fix":"Implement workarounds to prevent duplicate telemetry, such as carefully managing logging configurations to avoid overlapping instrumentation or disabling native logging if OpenTelemetry is fully configured.","message":"When using Azure Functions with the Azure Monitor OpenTelemetry Distro (for explicit OpenTelemetry instrumentation), enabling Azure Functions' native logging can result in duplicate telemetry entries in Application Insights.","severity":"gotcha","affected_versions":"All versions (when combined with Azure Functions native logging and OpenTelemetry Distro)"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z"}