1010from functools import singledispatch
1111from itertools import product
1212from pathlib import Path
13- from typing import Any , Optional , Tuple , TypeVar , Union
13+ from typing import Any , Dict , Optional , Tuple , TypeVar , Union
1414
1515from azure .ai .ml ._azure_environments import (
1616 CloudArgumentKeys ,
4343 AzureMachineLearningWorkspaces as ServiceClientWorkspaceDataplane ,
4444)
4545from 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
4747from azure .ai .ml ._user_agent import USER_AGENT
4848from azure .ai .ml ._utils ._experimental import experimental
4949from 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 (
0 commit comments