Skip to content

Commit 59a042b

Browse files
log request ids
1 parent bccfa31 commit 59a042b

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

ads/aqua/extension/base_handler.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/usr/bin/env python
2-
# -*- coding: utf-8 -*-
3-
# Copyright (c) 2024 Oracle and/or its affiliates.
2+
# Copyright (c) 2025 Oracle and/or its affiliates.
43
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
54

65

@@ -35,7 +34,7 @@ def __init__(
3534
self.telemetry = TelemetryClient(
3635
bucket=AQUA_TELEMETRY_BUCKET, namespace=AQUA_TELEMETRY_BUCKET_NS
3736
)
38-
except:
37+
except Exception:
3938
pass
4039

4140
@staticmethod
@@ -82,19 +81,23 @@ def write_error(self, status_code, **kwargs):
8281
"message": message,
8382
"service_payload": service_payload,
8483
"reason": reason,
84+
"request_id": str(uuid.uuid4()),
8585
}
8686
exc_info = kwargs.get("exc_info")
8787
if exc_info:
88-
logger.error("".join(traceback.format_exception(*exc_info)))
88+
logger.error(
89+
f"Error Request ID: {reply['request_id']}\n"
90+
f"Error: {''.join(traceback.format_exception(*exc_info))}"
91+
)
8992
e = exc_info[1]
9093
if isinstance(e, HTTPError):
9194
reply["message"] = e.log_message or message
9295
reply["reason"] = e.reason if e.reason else reply["reason"]
93-
reply["request_id"] = str(uuid.uuid4())
94-
else:
95-
reply["request_id"] = str(uuid.uuid4())
9696

97-
logger.warning(reply["message"])
97+
logger.error(
98+
f"Error Request ID: {reply['request_id']}\n"
99+
f"Error: {reply['message']} {reply['reason']}"
100+
)
98101

99102
# telemetry may not be present if there is an error while initializing
100103
if hasattr(self, "telemetry"):
@@ -103,7 +106,7 @@ def write_error(self, status_code, **kwargs):
103106
category="aqua/error",
104107
action=str(status_code),
105108
value=reason,
106-
**aqua_api_details
109+
**aqua_api_details,
107110
)
108111

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

0 commit comments

Comments
 (0)