Skip to content

Commit c92ee71

Browse files
Telemetry migration from opencensus to azure monitor opentelemetry (Azure#37392)
* pre-commit hook changes * use prod credentials * fix unit tests * add missing dependency * remove unnecessary dependency * add dependency * remove opentelemetry-api * add azure monitor dependency in setup * add and remove dependencies * remove from dev_requirements * add new line * readd dependencies due to azure identity issues
1 parent 2e19c52 commit c92ee71

36 files changed

+175
-313
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
### Bugs Fixed
99
- #35820 - using compute location attribute to fill compute location to align the experience with UI.
1010

11+
### Other Changes
12+
- Added dependency on `azure-monitor-opentelemetry`.
1113

1214
## 1.20.0 (2024-09-10)
1315

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

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from functools import singledispatch
1111
from itertools import product
1212
from pathlib import Path
13-
from typing import Any, Dict, Optional, Tuple, TypeVar, Union
13+
from typing import Any, Optional, Tuple, TypeVar, Union
1414

1515
from azure.ai.ml._azure_environments import (
1616
CloudArgumentKeys,
@@ -43,7 +43,7 @@
4343
AzureMachineLearningWorkspaces as ServiceClientWorkspaceDataplane,
4444
)
4545
from azure.ai.ml._scope_dependent_operations import OperationConfig, OperationsContainer, OperationScope
46-
from azure.ai.ml._telemetry.logging_handler import get_appinsights_log_handler
46+
from azure.ai.ml._telemetry.logging_handler import set_appinsights_distro
4747
from azure.ai.ml._user_agent import USER_AGENT
4848
from azure.ai.ml._utils._experimental import experimental
4949
from azure.ai.ml._utils._http_utils import HttpPipeline
@@ -278,12 +278,11 @@ def __init__(
278278

279279
user_agent = kwargs.get("user_agent", None)
280280

281-
app_insights_handler: Tuple = get_appinsights_log_handler(
281+
set_appinsights_distro(
282282
user_agent,
283283
**{"properties": properties},
284284
enable_telemetry=self._operation_config.enable_telemetry,
285285
)
286-
app_insights_handler_kwargs: Dict[str, Tuple] = {"app_insights_handler": app_insights_handler}
287286

288287
base_url = _get_base_url_from_metadata(cloud_name=cloud_name, is_local_mfe=True)
289288
self._base_url = base_url
@@ -292,7 +291,7 @@ def __init__(
292291
self._operation_container = OperationsContainer()
293292

294293
# kwargs related to operations alone not all kwargs passed to MLClient are needed by operations
295-
ops_kwargs = app_insights_handler_kwargs
294+
ops_kwargs = {}
296295
if base_url:
297296
ops_kwargs["enforce_https"] = _is_https_url(base_url)
298297

@@ -479,7 +478,6 @@ def __init__(
479478
self._credential,
480479
requests_pipeline=self._requests_pipeline,
481480
dataplane_client=self._service_client_workspace_dataplane,
482-
**app_insights_handler_kwargs,
483481
)
484482
self._operation_container.add(AzureMLResourceType.WORKSPACE, self._workspaces) # type: ignore[arg-type]
485483

@@ -497,7 +495,6 @@ def __init__(
497495
self._service_client_10_2022_preview,
498496
self._operation_container,
499497
self._credential,
500-
**app_insights_handler_kwargs, # type: ignore[arg-type]
501498
)
502499
self._operation_container.add(AzureMLResourceType.REGISTRY, self._registries) # type: ignore[arg-type]
503500

@@ -519,7 +516,6 @@ def __init__(
519516
self._operation_config,
520517
self._service_client_08_2023_preview,
521518
self._service_client_04_2024_preview,
522-
**app_insights_handler_kwargs, # type: ignore[arg-type]
523519
)
524520
self._operation_container.add(AzureMLResourceType.COMPUTE, self._compute)
525521
self._datastores = DatastoreOperations(
@@ -545,7 +541,6 @@ def __init__(
545541
workspace_rg=self._ws_rg,
546542
workspace_sub=self._ws_sub,
547543
registry_reference=registry_reference,
548-
**app_insights_handler_kwargs, # type: ignore[arg-type]
549544
)
550545
# Evaluators
551546
self._evaluators = EvaluatorOperations(
@@ -563,7 +558,6 @@ def __init__(
563558
workspace_rg=self._ws_rg,
564559
workspace_sub=self._ws_sub,
565560
registry_reference=registry_reference,
566-
**app_insights_handler_kwargs, # type: ignore[arg-type]
567561
)
568562

569563
self._operation_container.add(AzureMLResourceType.MODEL, self._models)
@@ -705,7 +699,6 @@ def __init__(
705699
self._service_client_07_2024_preview,
706700
self._operation_container,
707701
self._credential,
708-
**app_insights_handler_kwargs, # type: ignore[arg-type]
709702
)
710703

711704
self._featuresets = FeatureSetOperations(

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
__path__ = __import__("pkgutil").extend_path(__path__, __name__)
66

77
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
8+
from .logging_handler import AML_INTERNAL_LOGGER_NAMESPACE, set_appinsights_distro
99

1010
__all__ = [
1111
"monitor_with_activity",
1212
"monitor_with_telemetry_mixin",
1313
"log_activity",
1414
"ActivityType",
15-
"get_appinsights_log_handler",
15+
"set_appinsights_distro",
1616
"AML_INTERNAL_LOGGER_NAMESPACE",
1717
]

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
# Get environment variable IS_IN_CI_PIPELINE to decide whether it's in CI test
3232
IS_IN_CI_PIPELINE = _str_to_bool(os.environ.get("IS_IN_CI_PIPELINE", "False"))
3333

34+
ACTIVITY_SPAN = "activity_span"
35+
3436

3537
class ActivityType(object):
3638
"""The type of activity (code) monitored.
@@ -93,10 +95,7 @@ def process(self, msg: str, kwargs: Dict) -> Tuple[str, Dict]: # type: ignore[o
9395
if "extra" not in kwargs:
9496
kwargs["extra"] = {}
9597

96-
if "properties" not in kwargs["extra"]:
97-
kwargs["extra"]["properties"] = {}
98-
99-
kwargs["extra"]["properties"].update(self._activity_info)
98+
kwargs["extra"].update(self._activity_info)
10099

101100
return msg, kwargs
102101

@@ -282,7 +281,7 @@ def monitor(f):
282281
def wrapper(*args, **kwargs):
283282
tracer = logger.package_tracer if isinstance(logger, OpsLogger) else None
284283
if tracer:
285-
with tracer.span():
284+
with tracer.start_as_current_span(ACTIVITY_SPAN):
286285
with log_activity(
287286
logger.package_logger, activity_name or f.__name__, activity_type, custom_dimensions
288287
):

0 commit comments

Comments
 (0)