diff options
author | Erik Johnston <erik@matrix.org> | 2016-08-19 18:49:37 +0100 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2016-08-19 18:49:37 +0100 |
commit | 27e0178da9e5c61c5221faf4a7ad1b5be5684531 (patch) | |
tree | 37af80cdcbbbbb849cf3d3a24cd5022a12c94545 /synapse/http | |
parent | Remove redundant measure (diff) | |
download | synapse-27e0178da9e5c61c5221faf4a7ad1b5be5684531.tar.xz |
Add a top level measure
Diffstat (limited to 'synapse/http')
-rw-r--r-- | synapse/http/server.py | 91 |
1 files changed, 46 insertions, 45 deletions
diff --git a/synapse/http/server.py b/synapse/http/server.py index 74840de55c..2cba13e69f 100644 --- a/synapse/http/server.py +++ b/synapse/http/server.py @@ -104,54 +104,55 @@ def wrap_request_handler(request_handler, report_metrics): _next_request_id += 1 with LoggingContext(request_id) as request_context: - if report_metrics: - request_metrics = RequestMetrics() - request_metrics.start(self.clock) - - request_context.request = request_id - with request.processing(): - try: - with PreserveLoggingContext(request_context): - yield request_handler(self, request) - except CodeMessageException as e: - code = e.code - if isinstance(e, SynapseError): - logger.info( - "%s SynapseError: %s - %s", request, code, e.msg - ) - else: - logger.exception(e) - outgoing_responses_counter.inc(request.method, str(code)) - respond_with_json( - request, code, cs_exception(e), send_cors=True, - pretty_print=_request_user_agent_is_curl(request), - version_string=self.version_string, - ) - except: - logger.exception( - "Failed handle request %s.%s on %r: %r", - request_handler.__module__, - request_handler.__name__, - self, - request - ) - respond_with_json( - request, - 500, - { - "error": "Internal server error", - "errcode": Codes.UNKNOWN, - }, - send_cors=True - ) - finally: + with Measure(self.clock, "wrapped_request_handler"): + if report_metrics: + request_metrics = RequestMetrics() + request_metrics.start(self.clock) + + request_context.request = request_id + with request.processing(): try: - if report_metrics: - request_metrics.stop( - self.clock, request, self.__class__.__name__ + with PreserveLoggingContext(request_context): + yield request_handler(self, request) + except CodeMessageException as e: + code = e.code + if isinstance(e, SynapseError): + logger.info( + "%s SynapseError: %s - %s", request, code, e.msg ) + else: + logger.exception(e) + outgoing_responses_counter.inc(request.method, str(code)) + respond_with_json( + request, code, cs_exception(e), send_cors=True, + pretty_print=_request_user_agent_is_curl(request), + version_string=self.version_string, + ) except: - pass + logger.exception( + "Failed handle request %s.%s on %r: %r", + request_handler.__module__, + request_handler.__name__, + self, + request + ) + respond_with_json( + request, + 500, + { + "error": "Internal server error", + "errcode": Codes.UNKNOWN, + }, + send_cors=True + ) + finally: + try: + if report_metrics: + request_metrics.stop( + self.clock, request, self.__class__.__name__ + ) + except: + pass return wrapped_request_handler |