Skip to content

Commit d42433b

Browse files
Revert "Telemetry migration from opencensus to azure monitor opentelemetry" (Azure#37630)
* Revert "Telemetry migration from opencensus to azure monitor opentelemetry (#…" This reverts commit c92ee71. * add codeowners * add codeowners
1 parent 54b2d37 commit d42433b

36 files changed

+313
-175
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
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`.
1311

1412
## 1.20.0 (2024-09-10)
1513

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

Lines changed: 11 additions & 4 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, Optional, Tuple, TypeVar, Union
13+
from typing import Any, Dict, 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 set_appinsights_distro
46+
from azure.ai.ml._telemetry.logging_handler import get_appinsights_log_handler
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,11 +278,12 @@ def __init__(
278278

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

281-
set_appinsights_distro(
281+
app_insights_handler: Tuple = get_appinsights_log_handler(
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}
286287

287288
base_url = _get_base_url_from_metadata(cloud_name=cloud_name, is_local_mfe=True)
288289
self._base_url = base_url
@@ -291,7 +292,7 @@ def __init__(
291292
self._operation_container = OperationsContainer()
292293

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

@@ -478,6 +479,7 @@ def __init__(
478479
self._credential,
479480
requests_pipeline=self._requests_pipeline,
480481
dataplane_client=self._service_client_workspace_dataplane,
482+
**app_insights_handler_kwargs,
481483
)
482484
self._operation_container.add(AzureMLResourceType.WORKSPACE, self._workspaces) # type: ignore[arg-type]
483485

@@ -495,6 +497,7 @@ def __init__(
495497
self._service_client_10_2022_preview,
496498
self._operation_container,
497499
self._credential,
500+
**app_insights_handler_kwargs, # type: ignore[arg-type]
498501
)
499502
self._operation_container.add(AzureMLResourceType.REGISTRY, self._registries) # type: ignore[arg-type]
500503

@@ -516,6 +519,7 @@ def __init__(
516519
self._operation_config,
517520
self._service_client_08_2023_preview,
518521
self._service_client_04_2024_preview,
522+
**app_insights_handler_kwargs, # type: ignore[arg-type]
519523
)
520524
self._operation_container.add(AzureMLResourceType.COMPUTE, self._compute)
521525
self._datastores = DatastoreOperations(
@@ -541,6 +545,7 @@ def __init__(
541545
workspace_rg=self._ws_rg,
542546
workspace_sub=self._ws_sub,
543547
registry_reference=registry_reference,
548+
**app_insights_handler_kwargs, # type: ignore[arg-type]
544549
)
545550
# Evaluators
546551
self._evaluators = EvaluatorOperations(
@@ -558,6 +563,7 @@ def __init__(
558563
workspace_rg=self._ws_rg,
559564
workspace_sub=self._ws_sub,
560565
registry_reference=registry_reference,
566+
**app_insights_handler_kwargs, # type: ignore[arg-type]
561567
)
562568

563569
self._operation_container.add(AzureMLResourceType.MODEL, self._models)
@@ -699,6 +705,7 @@ def __init__(
699705
self._service_client_07_2024_preview,
700706
self._operation_container,
701707
self._credential,
708+
**app_insights_handler_kwargs, # type: ignore[arg-type]
702709
)
703710

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

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

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
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-
3634

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

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

100101
return msg, kwargs
101102

@@ -281,7 +282,7 @@ def monitor(f):
281282
def wrapper(*args, **kwargs):
282283
tracer = logger.package_tracer if isinstance(logger, OpsLogger) else None
283284
if tracer:
284-
with tracer.start_as_current_span(ACTIVITY_SPAN):
285+
with tracer.span():
285286
with log_activity(
286287
logger.package_logger, activity_name or f.__name__, activity_type, custom_dimensions
287288
):

0 commit comments

Comments
 (0)