# HG changeset patch # User RhodeCode Admin # Date 2022-11-03 08:40:25 # Node ID bfc036f69eec4c96a169e7b3894b33356cbf2c68 # Parent 0f88a70ebdcbf6dc3c9cfd699407b6b6cdf7c2a9 metrics: expose response code to logs diff --git a/rhodecode/lib/middleware/request_wrapper.py b/rhodecode/lib/middleware/request_wrapper.py --- a/rhodecode/lib/middleware/request_wrapper.py +++ b/rhodecode/lib/middleware/request_wrapper.py @@ -56,6 +56,7 @@ class RequestWrapperTween(object): _auth_user = self._get_user_info(request) ip = get_ip_addr(request.environ) match_route = request.matched_route.name if request.matched_route else "NOT_FOUND" + resp_code = getattr(response, 'status_code', 'UNDEFINED') total = time.time() - start log.info( @@ -63,12 +64,11 @@ class RequestWrapperTween(object): count, _auth_user, request.environ.get('REQUEST_METHOD'), _path, total, get_user_agent(request. environ), _ver_, extra={"time": total, "ver": _ver_, "ip": ip, - "path": _path, "view_name": match_route} + "path": _path, "view_name": match_route, "code": resp_code} ) statsd = request.registry.statsd if statsd: - resp_code = getattr(response, 'status_code', 'UNDEFINED') elapsed_time_ms = round(1000.0 * total) # use ms only statsd.timing( "rhodecode_req_timing.histogram", elapsed_time_ms,