コード例 #1
0
    def parse_response(self, url: str, status_code: int, headers: dict,
                       body: bytes) -> dict:
        max_size = Configuration.get_max_entry_size(
            has_error=is_error_code(status_code))
        if Configuration.verbose and not should_scrub_domain(url):
            additional_info = {
                "headers": lumigo_dumps(headers, max_size),
                "body": lumigo_dumps(body, max_size) if body else "",
                "statusCode": status_code,
            }
        else:
            additional_info = {
                "statusCode": status_code,
                "body": "The data is not available"
            }

        return {
            "type": HTTP_TYPE,
            "info": {
                "httpInfo": {
                    "host": url,
                    "response": additional_info
                }
            },
            "ended": get_current_ms_time(),
        }
コード例 #2
0
def update_event_response(host: Optional[str], status_code: int, headers: dict,
                          body: bytes) -> None:
    """
    :param host: If None, use the host from the last span, otherwise this is the first chuck and we can empty
                        the aggregated response body
    This function assumes synchronous execution - we update the last http event.
    """
    if is_lumigo_edge(host):
        return
    last_event = SpansContainer.get_span().pop_last_span()
    if last_event:
        http_info = last_event.get("info", {}).get("httpInfo", {})
        if not host:
            host = http_info.get("host", "unknown")
        else:
            HttpState.previous_response_body = b""

        has_error = is_error_code(status_code)
        max_size = Configuration.get_max_entry_size(has_error)
        headers = {k.lower(): v for k, v in headers.items()} if headers else {}
        parser = get_parser(host, headers)()  # type: ignore
        if len(HttpState.previous_response_body) < max_size:
            HttpState.previous_response_body += body
        if has_error:
            _update_request_data_increased_size_limit(http_info, max_size)
        update = parser.parse_response(  # type: ignore
            host,
            status_code,
            headers,
            HttpState.previous_response_body  # type: ignore
        )
        SpansContainer.get_span().add_span(
            recursive_json_join(update, last_event))
コード例 #3
0
def test_is_error_code(status_code, is_error):
    assert is_error_code(status_code) is is_error