summary refs log tree commit diff
path: root/synapse/http
diff options
context:
space:
mode:
authorRichard van der Hoff <richard@matrix.org>2018-05-09 18:03:04 +0100
committerRichard van der Hoff <richard@matrix.org>2018-05-10 12:19:52 +0100
commitb8700dd7d0482813beb9c780b411de5108ae078a (patch)
tree0df913a0e9573fbdfbdabd4bc3c3d1fc8478ea4f /synapse/http
parentMove RequestMetrics handling into SynapseRequest.processing() (diff)
downloadsynapse-b8700dd7d0482813beb9c780b411de5108ae078a.tar.xz
Bump requests_counter in wrapped_request_handler
less magic
Diffstat (limited to '')
-rw-r--r--synapse/http/server.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/synapse/http/server.py b/synapse/http/server.py
index 8e5d1d58f5..1d05b53873 100644
--- a/synapse/http/server.py
+++ b/synapse/http/server.py
@@ -90,12 +90,20 @@ def wrap_request_handler(request_handler, include_metrics=False):
                     try:
                         with PreserveLoggingContext(request_context):
                             if include_metrics:
-                                yield request_handler(
+                                d = request_handler(
                                     self, request, request.request_metrics,
                                 )
                             else:
-                                requests_counter.inc(request.method, servlet_name)
-                                yield request_handler(self, request)
+                                d = request_handler(self, request)
+
+                            # record the arrival of the request *after*
+                            # dispatching to the handler, so that the handler
+                            # can update the servlet name in the request
+                            # metrics
+                            requests_counter.inc(request.method,
+                                                 request.request_metrics.name)
+                            yield d
+
                     except CodeMessageException as e:
                         code = e.code
                         if isinstance(e, SynapseError):
@@ -220,7 +228,6 @@ class JsonResource(HttpServer, resource.Resource):
             servlet_classname = "%r" % callback
 
         request_metrics.name = servlet_classname
-        requests_counter.inc(request.method, servlet_classname)
 
         # Now trigger the callback. If it returns a response, we send it
         # here. If it throws an exception, that is handled by the wrapper