diff --git a/ads/aqua/common/decorator.py b/ads/aqua/common/decorator.py index b697afff2..d03805ab2 100644 --- a/ads/aqua/common/decorator.py +++ b/ads/aqua/common/decorator.py @@ -69,6 +69,16 @@ def inner_function( reason=error.message, service_payload=error.args[0] if error.args else None, exc_info=sys.exc_info(), + aqua_api_details=dict( + # __qualname__ gives information of class and name of api + aqua_api_name=func.__qualname__, + oci_api_name=getattr( + error, "operation_name", "Unknown OCI Operation" + ), + service_endpoint=getattr( + error, "request_endpoint", "Unknown Request Endpoint" + ) + ) ) except ( ClientError, diff --git a/ads/aqua/extension/aqua_ws_msg_handler.py b/ads/aqua/extension/aqua_ws_msg_handler.py index 1494ce028..04ff651f4 100644 --- a/ads/aqua/extension/aqua_ws_msg_handler.py +++ b/ads/aqua/extension/aqua_ws_msg_handler.py @@ -78,10 +78,12 @@ def write_error(self, status_code, **kwargs): logger.warning(reply["message"]) # telemetry may not be present if there is an error while initializing if hasattr(self, "telemetry"): + aqua_api_details = kwargs.get("aqua_api_details", {}) self.telemetry.record_event_async( category="aqua/error", action=str(status_code), value=reason, + **aqua_api_details ) response = AquaWsError( status=status_code, diff --git a/ads/aqua/extension/base_handler.py b/ads/aqua/extension/base_handler.py index d84602bf7..5bd9f7091 100644 --- a/ads/aqua/extension/base_handler.py +++ b/ads/aqua/extension/base_handler.py @@ -98,10 +98,12 @@ def write_error(self, status_code, **kwargs): # telemetry may not be present if there is an error while initializing if hasattr(self, "telemetry"): + aqua_api_details = kwargs.get("aqua_api_details", {}) self.telemetry.record_event_async( category="aqua/error", action=str(status_code), value=reason, + **aqua_api_details ) self.finish(json.dumps(reply)) diff --git a/tests/unitary/with_extras/aqua/test_handlers.py b/tests/unitary/with_extras/aqua/test_handlers.py index 74b9853b4..a4ae749e9 100644 --- a/tests/unitary/with_extras/aqua/test_handlers.py +++ b/tests/unitary/with_extras/aqua/test_handlers.py @@ -129,6 +129,11 @@ def test_finish(self, name, payload, expected_call, mock_super_finish): ), None, ), + aqua_api_details=dict( + aqua_api_name="TestDataset.create", + oci_api_name=TestDataset.mock_service_payload_create["operation_name"], + service_endpoint=TestDataset.mock_service_payload_create["request_endpoint"] + ) ), "Authorization Failed: The resource you're looking for isn't accessible. Operation Name: get_job_run.", ], @@ -159,12 +164,14 @@ def test_write_error(self, name, input, expected_msg, mock_uuid, mock_logger): "request_id": "1234", } self.test_instance.finish.assert_called_once_with(json.dumps(expected_reply)) + aqua_api_details = input.get("aqua_api_details", {}) self.test_instance.telemetry.record_event_async.assert_called_with( category="aqua/error", action=str( input.get("status_code"), ), value=input.get("reason"), + **aqua_api_details ) mock_logger.warning.assert_called_with(expected_msg)