From 65645f1efdc15eb5fb7ef7c991452b1981c48ab8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Brunner?= Date: Tue, 12 Nov 2024 10:04:50 +0100 Subject: [PATCH] Add a log on failing route --- c2cwsgiutils/stats_pyramid/_pyramid_spy.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/c2cwsgiutils/stats_pyramid/_pyramid_spy.py b/c2cwsgiutils/stats_pyramid/_pyramid_spy.py index 0c701de8e..c95c66a45 100644 --- a/c2cwsgiutils/stats_pyramid/_pyramid_spy.py +++ b/c2cwsgiutils/stats_pyramid/_pyramid_spy.py @@ -1,3 +1,4 @@ +import logging import time from typing import Callable, Optional @@ -9,6 +10,8 @@ from c2cwsgiutils import prometheus +_LOG = logging.getLogger(__name__) + _PROMETHEUS_PYRAMID_ROUTES_SUMMARY = prometheus_client.Summary( prometheus.build_metric_name("pyramid_routes"), "Pyramid routes", @@ -61,6 +64,15 @@ def finished_cb(request: pyramid.request.Request) -> None: name = request.matched_route.name if kind == "route": _add_server_metric(request, "route", description=name) + if status >= 500: + _LOG.warning( + "Request %s %s %s route %s return status %s", + request.method, + request.path, + kind, + name, + status, + ) measure.labels( method=request.method, route=name, status=status, group=str(status // 100 * 100) ).observe(time.process_time() - start)