Skip to content

Commit 14c0906

Browse files
Unexclude _telemetry folder (#34012)
* unexclude _telemetry folder * fix activity.py * fix activity.py - 2
1 parent 1b58096 commit 14c0906

File tree

4 files changed

+25
-22
lines changed

4 files changed

+25
-22
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import sys
1111
import traceback
1212
import types
13-
from typing import Iterable, List, Optional, Type
13+
from typing import Any, Generator, List, Optional, Type
1414

1515

1616
class _CustomStackSummary(traceback.StackSummary):
@@ -86,7 +86,7 @@ def __init__(
8686
self.exc_type = exc_type
8787
# Capture now to permit freeing resources: only complication is in the
8888
# unofficial API _format_final_exc_line
89-
self._str = traceback._some_str(exc_value)
89+
self._str = traceback._some_str(exc_value) # pylint: disable=no-member
9090
if exc_type and issubclass(exc_type, SyntaxError):
9191
# Handle SyntaxError's specially
9292
self.filename = exc_value.filename
@@ -97,7 +97,7 @@ def __init__(
9797
if lookup_lines:
9898
self._load_lines()
9999

100-
def format_exception_only(self) -> Iterable[str]:
100+
def format_exception_only(self) -> Generator:
101101
"""Format the exception part of the traceback.
102102
103103
:return: An iterable of strings, each ending in a newline. Normally, the generator emits a single
@@ -116,7 +116,7 @@ def format_exception_only(self) -> Iterable[str]:
116116
stype = smod + "." + stype
117117

118118
if not issubclass(self.exc_type, SyntaxError):
119-
yield traceback._format_final_exc_line(stype, self._str)
119+
yield traceback._format_final_exc_line(stype, self._str) # type: ignore[attr-defined]
120120
return
121121

122122
# It was a syntax error; show exactly where the problem was found.
@@ -129,7 +129,7 @@ def format_exception_only(self) -> Iterable[str]:
129129
if badline is not None:
130130
yield " {}\n".format(badline.strip())
131131
if offset is not None:
132-
caretspace = badline.rstrip("\n")
132+
caretspace: Any = badline.rstrip("\n")
133133
offset = min(len(caretspace), offset) - 1
134134
caretspace = caretspace[:offset].lstrip()
135135
# non-space whitespace (likes tabs) must be kept for alignment
@@ -149,7 +149,7 @@ def format_exc(limit: Optional[int] = None, chain: bool = True) -> str:
149149
:return: The formatted exception string
150150
:rtype: str
151151
"""
152-
return "".join(format_exception(*sys.exc_info(), limit=limit, chain=chain))
152+
return "".join(format_exception(*sys.exc_info(), limit=limit, chain=chain)) # type: ignore[misc]
153153

154154

155155
def format_exception( # pylint: disable=unused-argument

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

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import os
1919
import uuid
2020
from datetime import datetime
21-
from typing import Dict, Iterable, Tuple
21+
from typing import Any, Dict, Tuple
2222
from uuid import uuid4
2323

2424
from marshmallow import ValidationError
@@ -68,7 +68,7 @@ def __init__(self, logger: logging.Logger, activity_info: str):
6868
:type activity_info: str
6969
"""
7070
self._activity_info = activity_info
71-
super(ActivityLoggerAdapter, self).__init__(logger, None)
71+
super(ActivityLoggerAdapter, self).__init__(logger, None) # type: ignore[arg-type]
7272

7373
@property
7474
def activity_info(self) -> str:
@@ -79,7 +79,7 @@ def activity_info(self) -> str:
7979
"""
8080
return self._activity_info
8181

82-
def process(self, msg: str, kwargs: Dict) -> Tuple[str, Dict]:
82+
def process(self, msg: str, kwargs: Dict) -> Tuple[str, Dict]: # type: ignore[override]
8383
"""Process the log message.
8484
8585
:param msg: The log message.
@@ -158,7 +158,7 @@ def log_activity(
158158
activity_name,
159159
activity_type=ActivityType.INTERNALCALL,
160160
custom_dimensions=None,
161-
) -> Iterable[ActivityLoggerAdapter]:
161+
) -> Any:
162162
"""Log an activity.
163163
164164
An activity is a logical block of code that consumers want to monitor.
@@ -190,7 +190,7 @@ def log_activity(
190190
completion_status = ActivityCompletionStatus.SUCCESS
191191

192192
message = "ActivityStarted, {}".format(activity_name)
193-
activityLogger = ActivityLoggerAdapter(logger, activity_info)
193+
activityLogger = ActivityLoggerAdapter(logger, activity_info) # type: ignore[arg-type]
194194
activityLogger.info(message)
195195
exception = None
196196

@@ -207,7 +207,8 @@ def log_activity(
207207
in [ErrorCategory.SYSTEM_ERROR, ErrorCategory.UNKNOWN]
208208
) or (
209209
"errorCategory" in activityLogger.activity_info
210-
and activityLogger.activity_info["errorCategory"] in [ErrorCategory.SYSTEM_ERROR, ErrorCategory.UNKNOWN]
210+
and activityLogger.activity_info["errorCategory"] # type: ignore[index]
211+
in [ErrorCategory.SYSTEM_ERROR, ErrorCategory.UNKNOWN]
211212
):
212213
raise Exception("Got InternalSDKError", e) from e
213214
raise
@@ -217,25 +218,28 @@ def log_activity(
217218
end_time = datetime.utcnow()
218219
duration_ms = round((end_time - start_time).total_seconds() * 1000, 2)
219220

220-
activityLogger.activity_info["completionStatus"] = completion_status
221-
activityLogger.activity_info["durationMs"] = duration_ms
221+
activityLogger.activity_info["completionStatus"] = completion_status # type: ignore[index]
222+
activityLogger.activity_info["durationMs"] = duration_ms # type: ignore[index]
222223
message = "ActivityCompleted: Activity={}, HowEnded={}, Duration={} [ms]".format(
223224
activity_name, completion_status, duration_ms
224225
)
225226
if exception:
226227
message += ", Exception={}".format(type(exception).__name__)
227-
activityLogger.activity_info["exception"] = type(exception).__name__
228+
activityLogger.activity_info["exception"] = type(exception).__name__ # type: ignore[index]
228229
if isinstance(exception, MlException):
229-
activityLogger.activity_info[
230+
activityLogger.activity_info[ # type: ignore[index]
230231
"errorMessage"
231232
] = exception.no_personal_data_message # pylint: disable=no-member
232-
activityLogger.activity_info["errorTarget"] = exception.target # pylint: disable=no-member
233-
activityLogger.activity_info[
233+
# pylint: disable=no-member
234+
activityLogger.activity_info["errorTarget"] = exception.target # type: ignore[index]
235+
activityLogger.activity_info[ # type: ignore[index]
234236
"errorCategory"
235237
] = exception.error_category # pylint: disable=no-member
236238
if exception.inner_exception: # pylint: disable=no-member
237239
# pylint: disable=no-member
238-
activityLogger.activity_info["innerException"] = type(exception.inner_exception).__name__
240+
activityLogger.activity_info["innerException"] = type( # type: ignore[index]
241+
exception.inner_exception
242+
).__name__
239243
activityLogger.error(message)
240244
else:
241245
activityLogger.info(message)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class CustomDimensionsFilter(logging.Filter):
4141
def __init__(self, custom_dimensions=None): # pylint: disable=super-init-not-called
4242
self.custom_dimensions = custom_dimensions or {}
4343

44-
def filter(self, record: dict) -> bool:
44+
def filter(self, record: dict) -> bool: # type: ignore[override]
4545
"""Adds the default custom_dimensions into the current log record. Does not
4646
otherwise filter any records
4747
@@ -53,7 +53,7 @@ def filter(self, record: dict) -> bool:
5353

5454
custom_dimensions = self.custom_dimensions.copy()
5555
custom_dimensions.update(getattr(record, "custom_dimensions", {}))
56-
record.custom_dimensions = custom_dimensions
56+
record.custom_dimensions = custom_dimensions # type: ignore[attr-defined]
5757

5858
return True
5959

sdk/ml/azure-ai-ml/pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ exclude = [
3333
"azure/ai/ml/_file_utils/",
3434
"azure/ai/ml/_local_endpoints/",
3535
"azure/ai/ml/_logging/",
36-
"azure/ai/ml/_telemetry/",
3736
"azure/ai/ml/_utils",
3837
"azure/ai/ml/data_transfer/",
3938
"azure/ai/ml/parallel/",

0 commit comments

Comments
 (0)