Bump requests_counter in wrapped_request_handler

less magic
This commit is contained in:
Richard van der Hoff 2018-05-09 18:03:04 +01:00
parent c6f730282c
commit b8700dd7d0

View File

@ -90,12 +90,20 @@ def wrap_request_handler(request_handler, include_metrics=False):
try: try:
with PreserveLoggingContext(request_context): with PreserveLoggingContext(request_context):
if include_metrics: if include_metrics:
yield request_handler( d = request_handler(
self, request, request.request_metrics, self, request, request.request_metrics,
) )
else: else:
requests_counter.inc(request.method, servlet_name) d = request_handler(self, request)
yield 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: except CodeMessageException as e:
code = e.code code = e.code
if isinstance(e, SynapseError): if isinstance(e, SynapseError):
@ -220,7 +228,6 @@ class JsonResource(HttpServer, resource.Resource):
servlet_classname = "%r" % callback servlet_classname = "%r" % callback
request_metrics.name = servlet_classname request_metrics.name = servlet_classname
requests_counter.inc(request.method, servlet_classname)
# Now trigger the callback. If it returns a response, we send it # Now trigger the callback. If it returns a response, we send it
# here. If it throws an exception, that is handled by the wrapper # here. If it throws an exception, that is handled by the wrapper