Skip to content

Commit c718759

Browse files
authored
[ml] Fix bug in logs where error information wasn't passing through (#35056)
* Remove Optional type annotation from get() methods * Remove duplicate overloads * Update logging to include error category and message * Revert change to jupyter notebook logging check * Fix typing
1 parent ff2afe7 commit c718759

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,23 +60,23 @@ class ActivityLoggerAdapter(logging.LoggerAdapter):
6060
:type activity_info: str
6161
"""
6262

63-
def __init__(self, logger: logging.Logger, activity_info: str):
63+
def __init__(self, logger: logging.Logger, activity_info: Dict):
6464
"""Initialize a new instance of the class.
6565
6666
:param logger: The activity logger.
6767
:type logger: logging.Logger
6868
:param activity_info: The info to write to the logger.
69-
:type activity_info: str
69+
:type activity_info: Dict
7070
"""
7171
self._activity_info = activity_info
7272
super(ActivityLoggerAdapter, self).__init__(logger, None) # type: ignore[arg-type]
7373

7474
@property
75-
def activity_info(self) -> str:
75+
def activity_info(self) -> Dict:
7676
"""Return current activity info.
7777
7878
:return: The info to write to the logger
79-
:rtype: str
79+
:rtype: Dict
8080
"""
8181
return self._activity_info
8282

@@ -225,7 +225,6 @@ def log_activity(
225225
activity_name, completion_status, duration_ms
226226
)
227227
if exception:
228-
message += ", Exception={}".format(type(exception).__name__)
229228
activityLogger.activity_info["exception"] = type(exception).__name__ # type: ignore[index]
230229
if isinstance(exception, MlException):
231230
activityLogger.activity_info[ # type: ignore[index]
@@ -241,9 +240,14 @@ def log_activity(
241240
activityLogger.activity_info["innerException"] = type( # type: ignore[index]
242241
exception.inner_exception
243242
).__name__
243+
message += ", Exception={}".format(activityLogger.activity_info["exception"])
244+
message += ", ErrorCategory={}".format(activityLogger.activity_info["errorCategory"])
245+
message += ", ErrorMessage={}".format(activityLogger.activity_info["errorMessage"])
246+
244247
activityLogger.error(message)
245248
else:
246249
activityLogger.info(message)
250+
247251
except Exception: # pylint: disable=broad-except
248252
return # pylint: disable=lost-exception
249253

0 commit comments

Comments
 (0)