Skip to content

Commit

Permalink
Add cause label to api.unhandled_errors_total (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
lalinsky authored Feb 21, 2024
1 parent 0402dc2 commit 4c22a86
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions acoustid/api/v2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,16 @@ def handle(self, req):
raise errors.RequestTooLargeError()
except HTTPException:
raise
except Exception:
except Exception as exc:
if self.ctx.statsd is not None:
exc_str = str(exc)
cause = "unknown"
if "redis" in exc_str:
cause = "redis"
elif "sqlalchemy" in exc_str or "psycopg2" in exc_str:
cause = "postgres"
self.ctx.statsd.incr(
"api.unhandled_errors_total,request={}".format(request_type)
f"api.unhandled_errors_total,request={request_type},cause={cause}"
)
logger.exception("Error while handling API request")
raise errors.InternalError()
Expand Down

0 comments on commit 4c22a86

Please sign in to comment.