def __collect_trace_data(self, request, response, error, latency):
        """
        Collects the tracing data from the given parameters.
        :param request: The Flask request.
        :param response: The flask response.
        :param error: The error occurred if any.
        :param latency: The time elapsed to process the request.
        :return: The tracing data.
        """

        data = OrderedDict()
        data['latency'] = latency.elapsed
        data['request_method'] = request.environ['REQUEST_METHOD']
        data['request_url'] = request.url
        data['request_headers'] = request.headers

        body = request.get_data(as_text=True)
        if body:
            data['request_body'] = body

        if response:
            data['response_status'] = response.status_code

        if error:
            data['error'] = str(error)

        return data