Skip to content

Commit 483fb13

Browse files
committed
Add API request logging
1 parent 8515470 commit 483fb13

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

pkg/workloads/cortex/onnx_serve/api.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,21 @@ def get_signature(app_name, api_name):
208208
return jsonify(response)
209209

210210

211+
@app.after_request
212+
def after_request(response):
213+
if request.full_path.startswith("/healthz"):
214+
return response
215+
216+
logger.info("[%s] %s", util.now_timestamp_rfc_3339(), response.status)
217+
return response
218+
219+
220+
@app.errorhandler(Exception)
221+
def exceptions(e):
222+
logger.exception(e)
223+
return jsonify(error=str(e)), 500
224+
225+
211226
def start(args):
212227
api = None
213228
try:

pkg/workloads/cortex/tf_api/api.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,21 @@ def predict(deployment_name, api_name):
398398
return jsonify(response)
399399

400400

401+
@app.after_request
402+
def after_request(response):
403+
if request.full_path.startswith("/healthz"):
404+
return response
405+
406+
logger.info("[%s] %s", util.now_timestamp_rfc_3339(), response.status)
407+
return response
408+
409+
410+
@app.errorhandler(Exception)
411+
def exceptions(e):
412+
logger.exception(e)
413+
return jsonify(error=str(e)), 500
414+
415+
401416
def extract_signature():
402417
signature_def = local_cache["metadata"]["signatureDef"]
403418
if signature_def.get("predict") is None or signature_def["predict"].get("inputs") is None:

0 commit comments

Comments
 (0)