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))
def add_request_event(parse_params: HttpRequest): """ This function parses an request event and add it to the span. """ if is_lumigo_edge(parse_params.host): return parser = get_parser(parse_params.host)() msg = parser.parse_request(parse_params) HttpState.previous_request = parse_params SpansContainer.get_span().add_span(msg)
def add_request_event(span_id: Optional[str], parse_params: HttpRequest) -> Dict: """ This function parses an request event and add it to the span. """ if is_lumigo_edge(parse_params.host): return {} parser = get_parser(parse_params.host)() msg = parser.parse_request(parse_params) if span_id: msg["id"] = span_id HttpState.previous_request = parse_params new_span = SpansContainer.get_span().add_span(msg) HttpState.previous_span_id = new_span["id"] return new_span
def test_get_default_parser_when_using_extension(monkeypatch): monkeypatch.setenv("LUMIGO_USE_TRACER_EXTENSION", "TRUE") url = "https://ne3kjv28fh.execute-api.us-west-2.amazonaws.com/doriaviram" assert get_parser(url, {}) == Parser
def test_get_parser_apigw(): url = "https://ne3kjv28fh.execute-api.us-west-2.amazonaws.com/doriaviram" assert get_parser(url, {}) == ApiGatewayV2Parser
def test_get_parser_s3(): url = "s3.eu-west-1.amazonaws.com" headers = {"key": "value"} assert get_parser(url, headers) == S3Parser
def test_get_parser_check_headers(): url = "api.dev.com" headers = {"x-amzn-requestid": "1234"} assert get_parser(url, headers) == ServerlessAWSParser