def test_lambda_wrapper_exception(exc, context): @lumigo_tracer(token=TOKEN) def lambda_test_function(event, context): a = "A" # noqa raise exc try: lambda_test_function({}, context) except ValueError: pass else: assert False function_span = SpansContainer.get_span().function_span assert not SpansContainer.get_span().spans assert function_span.get("error", {}).get("type") == "ValueError" # Make sure no lumigo_tracer assert len(function_span["error"]["frames"]) == 1 assert function_span["error"]["frames"][0].pop("lineno") > 0 assert function_span["error"]["frames"][0] == { "function": "lambda_test_function", "fileName": __file__, "variables": { "a": '"A"', "context": f'"{str(context)}"', "event": "{}", "exc": f'"{str(exc)}"', }, } assert not function_span["id"].endswith("_started") assert "reporter_rtt" in function_span assert "maxFinishTime" not in function_span # Test that we can create an output message out of this span assert _create_request_body([function_span], prune_size_flag=False)
def test_create_request_body_keep_function_span_and_filter_other_spans( dummy_span, function_end_span ): expected_result = [dummy_span, dummy_span, dummy_span, function_end_span] size = _get_event_base64_size(expected_result) assert _create_request_body(expected_result * 2, True, size) == json.dumps( [function_end_span, dummy_span, dummy_span, dummy_span] )
def test_create_request_body_take_error_first(dummy_span, error_span, function_end_span): expected_result = [function_end_span, error_span, dummy_span, dummy_span] input = [ dummy_span, dummy_span, dummy_span, dummy_span, dummy_span, error_span, function_end_span, ] size = _get_event_base64_size(expected_result) assert _create_request_body(input, True, size) == json.dumps(expected_result)
def test_omitting_keys(context): @lumigo_tracer() def lambda_test_function(event, context): d = {"a": "b", "myPassword": "******"} conn = http.client.HTTPConnection("www.google.com") conn.request("POST", "/", json.dumps(d)) return {"secret_password": "******"} lambda_test_function({"key": "24"}, context) span = SpansContainer.get_span() assert span.function_span["return_value"] == '{"secret_password": "******"}' assert span.function_span["event"] == '{"key": "****"}' http_spans = list(SpansContainer.get_span().spans.values()) spans = json.loads(_create_request_body(http_spans, True)) assert spans[0]["info"]["httpInfo"]["request"]["body"] == json.dumps({ "a": "b", "myPassword": "******" })
def test_create_request_body_default(dummy_span): assert _create_request_body([dummy_span], False) == json.dumps([dummy_span])