Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved aqua telemetry #995

Merged
merged 4 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions ads/aqua/common/decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ 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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: I would rather suggest to use the get operator to extract attributes from error objects.

aqua_api_details = {
        "aqua_api_name": func.__qualname__,
        "oci_api_name": getattr(error, "operation_name", "Unknown Operation"),
        "service_endpoint": getattr(error, "request_endpoint", "Unknown Endpoint")
    }

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just updated

# __qualname__ gives information of class and name of api
aqua_api_name=func.__qualname__,
oci_api_name=error.operation_name,
service_endpoint=error.request_endpoint
)
)
except (
ClientError,
Expand Down
2 changes: 2 additions & 0 deletions ads/aqua/extension/aqua_ws_msg_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions ads/aqua/extension/base_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
7 changes: 7 additions & 0 deletions tests/unitary/with_extras/aqua/test_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
],
Expand Down Expand Up @@ -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)
Expand Down