Skip to content

Commit ab684e8

Browse files
authored
Improved aqua telemetry (#995)
2 parents 83eb229 + 44a3ae0 commit ab684e8

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

ads/aqua/common/decorator.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ def inner_function(
6969
reason=error.message,
7070
service_payload=error.args[0] if error.args else None,
7171
exc_info=sys.exc_info(),
72+
aqua_api_details=dict(
73+
# __qualname__ gives information of class and name of api
74+
aqua_api_name=func.__qualname__,
75+
oci_api_name=getattr(
76+
error, "operation_name", "Unknown OCI Operation"
77+
),
78+
service_endpoint=getattr(
79+
error, "request_endpoint", "Unknown Request Endpoint"
80+
)
81+
)
7282
)
7383
except (
7484
ClientError,

ads/aqua/extension/aqua_ws_msg_handler.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,12 @@ def write_error(self, status_code, **kwargs):
7878
logger.warning(reply["message"])
7979
# telemetry may not be present if there is an error while initializing
8080
if hasattr(self, "telemetry"):
81+
aqua_api_details = kwargs.get("aqua_api_details", {})
8182
self.telemetry.record_event_async(
8283
category="aqua/error",
8384
action=str(status_code),
8485
value=reason,
86+
**aqua_api_details
8587
)
8688
response = AquaWsError(
8789
status=status_code,

ads/aqua/extension/base_handler.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,12 @@ def write_error(self, status_code, **kwargs):
9898

9999
# telemetry may not be present if there is an error while initializing
100100
if hasattr(self, "telemetry"):
101+
aqua_api_details = kwargs.get("aqua_api_details", {})
101102
self.telemetry.record_event_async(
102103
category="aqua/error",
103104
action=str(status_code),
104105
value=reason,
106+
**aqua_api_details
105107
)
106108

107109
self.finish(json.dumps(reply))

tests/unitary/with_extras/aqua/test_handlers.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ def test_finish(self, name, payload, expected_call, mock_super_finish):
129129
),
130130
None,
131131
),
132+
aqua_api_details=dict(
133+
aqua_api_name="TestDataset.create",
134+
oci_api_name=TestDataset.mock_service_payload_create["operation_name"],
135+
service_endpoint=TestDataset.mock_service_payload_create["request_endpoint"]
136+
)
132137
),
133138
"Authorization Failed: The resource you're looking for isn't accessible. Operation Name: get_job_run.",
134139
],
@@ -159,12 +164,14 @@ def test_write_error(self, name, input, expected_msg, mock_uuid, mock_logger):
159164
"request_id": "1234",
160165
}
161166
self.test_instance.finish.assert_called_once_with(json.dumps(expected_reply))
167+
aqua_api_details = input.get("aqua_api_details", {})
162168
self.test_instance.telemetry.record_event_async.assert_called_with(
163169
category="aqua/error",
164170
action=str(
165171
input.get("status_code"),
166172
),
167173
value=input.get("reason"),
174+
**aqua_api_details
168175
)
169176

170177
mock_logger.warning.assert_called_with(expected_msg)

0 commit comments

Comments
 (0)