def process_response(self, req, resp, resource, req_succeeded=None): # req_succeded is not a kwarg in the API, but we need that to support # Falcon 1.0 that doesn't provide this argument span = self.tracer.current_span() if not span: return # unexpected status = httpx.normalize_status_code(resp.status) # FIXME[matt] falcon does not map errors or unmatched routes # to proper status codes, so we we have to try to infer them # here. See https://github.com/falconry/falcon/issues/606 if resource is None: status = '404' span.resource = "%s 404" % req.method span.set_tag(httpx.STATUS_CODE, status) span.finish() return err_type = sys.exc_info()[0] if err_type is not None: if req_succeeded is None: # backward-compatibility with Falcon 1.0; any version # greater than 1.0 has req_succeded in [True, False] # TODO[manu]: drop the support at some point status = _detect_and_set_status_error(err_type, span) elif req_succeeded is False: # Falcon 1.1+ provides that argument that is set to False # if get an Exception (404 is still an exception) status = _detect_and_set_status_error(err_type, span) span.set_tag(httpx.STATUS_CODE, status) span.finish()
def process_response(self, req, resp, resource, req_succeeded=None): # req_succeded is not a kwarg in the API, but we need that to support # Falcon 1.0 that doesn't provide this argument span = self.tracer.current_span() if not span: return # unexpected status = httpx.normalize_status_code(resp.status) # Note: any response header set after this line will not be stored in the span store_response_headers(resp._headers, span, config.falcon) # FIXME[matt] falcon does not map errors or unmatched routes # to proper status codes, so we we have to try to infer them # here. See https://github.com/falconry/falcon/issues/606 if resource is None: status = '404' span.resource = '%s 404' % req.method span.set_tag(httpx.STATUS_CODE, status) span.finish() return err_type = sys.exc_info()[0] if err_type is not None: if req_succeeded is None: # backward-compatibility with Falcon 1.0; any version # greater than 1.0 has req_succeded in [True, False] # TODO[manu]: drop the support at some point status = _detect_and_set_status_error(err_type, span) elif req_succeeded is False: # Falcon 1.1+ provides that argument that is set to False # if get an Exception (404 is still an exception) status = _detect_and_set_status_error(err_type, span) span.set_tag(httpx.STATUS_CODE, status) if 500 <= int(status) < 600: span.error = 1 # Emit span hook for this response # DEV: Emit before closing so they can overwrite `span.resource` if they want config.falcon.hooks.emit('request', span, req, resp) # Close the span span.finish()
def process_response(self, req, resp, resource): span = self.tracer.current_span() if not span: return # unexpected status = httpx.normalize_status_code(resp.status) # FIXME[matt] falcon does not map errors or unmatched routes # to proper status codes, so we we have to try to infer them # here. See https://github.com/falconry/falcon/issues/606 if resource is None: span.resource = "%s 404" % req.method status = '404' # If we have an active unhandled error, treat it as a 500 span.set_traceback() err_msg = span.get_tag(errx.ERROR_MSG) if err_msg and not _is_404(err_msg): status = '500' span.set_tag(httpx.STATUS_CODE, status) span.finish()