# HG changeset patch # User RhodeCode Admin # Date 2022-10-26 08:17:24 # Node ID e4831d789bf16505e5c0aef4205aadce6da0ece6 # Parent 1bd9683a8356ad0c2023e2435e785692fc86ed11 metrics: expose exc_type in consistent format diff --git a/rhodecode/api/__init__.py b/rhodecode/api/__init__.py --- a/rhodecode/api/__init__.py +++ b/rhodecode/api/__init__.py @@ -179,7 +179,9 @@ def exception_view(exc, request): statsd = request.registry.statsd if statsd: - statsd.incr('rhodecode_exception_total', tags=["exc_source:api", "type:{}".format(exc_info.type)]) + exc_type = "{}.{}".format(exc.__class__.__module__, exc.__class__.__name__) + statsd.incr('rhodecode_exception_total', + tags=["exc_source:api", "type:{}".format(exc_type)]) return jsonrpc_error(request, fault_message, rpc_id) diff --git a/rhodecode/config/middleware.py b/rhodecode/config/middleware.py --- a/rhodecode/config/middleware.py +++ b/rhodecode/config/middleware.py @@ -180,11 +180,6 @@ def error_handler(exception, request): log.exception( 'error occurred handling this request for path: %s', request.path) - statsd = request.registry.statsd - if statsd and base_response.status_code > 499: - statsd.incr('rhodecode_exception_total', - tags=["exc_source:web", "type:{}".format(base_response.status_code)]) - error_explanation = base_response.explanation or str(base_response) if base_response.status_code == 404: error_explanation += " Optionally you don't have permission to access this page." @@ -229,6 +224,14 @@ def error_handler(exception, request): '/errors/error_document.mako', {'c': c, 'h': helpers}, request=request, response=base_response) + statsd = request.registry.statsd + if statsd and base_response.status_code > 499: + exc_type = "{}.{}".format(exception.__class__.__module__, exception.__class__.__name__) + statsd.incr('rhodecode_exception_total', + tags=["exc_source:web", + "http_code:{}".format(base_response.status_code), + "type:{}".format(exc_type)]) + return response diff --git a/rhodecode/lib/celerylib/loader.py b/rhodecode/lib/celerylib/loader.py --- a/rhodecode/lib/celerylib/loader.py +++ b/rhodecode/lib/celerylib/loader.py @@ -179,7 +179,9 @@ def task_failure_signal( store_exception(id(exc_info), exc_info, prefix='rhodecode-celery') statsd = StatsdClient.statsd if statsd: - statsd.incr('rhodecode_exception_total', tags=["exc_source:celery", "type:{}".format(einfo.type)]) + exc_type = "{}.{}".format(einfo.__class__.__module__, einfo.__class__.__name__) + statsd.incr('rhodecode_exception_total', + tags=["exc_source:celery", "type:{}".format(exc_type)]) closer = celery_app.conf['PYRAMID_CLOSER'] if closer: 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 @@ -46,6 +46,7 @@ class RequestWrapperTween(object): def __call__(self, request): start = time.time() log.debug('Starting request time measurement') + response = None try: response = self.handler(request) finally: @@ -64,7 +65,7 @@ class RequestWrapperTween(object): statsd = request.registry.statsd if statsd: match_route = request.matched_route.name if request.matched_route else _path - resp_code = response.status_code + 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,