Repository: firecracker-microvm/firecracker
File: tests/integration_tests/functional/test_instrumented_firecracker.py (Python)

Code before:
            "show_level": True,
            "show_log_origin": True,
        }
        resp = vm.api.logger.put(**logger_config)
        assert resp.status_code == 204

        # Another API call after enabling TRACE
        resp = vm.api.describe.get()
        assert resp.status_code == 200

    finally:
        vm.kill()

    assert TRACE_LEVEL_HINT not in pre_tracing_log_data, (
        "TRACE level logs were found before setting log level to TRACE. "
    )

    pre_tracing_log_matches = re.findall(MARKER_REGEX, pre_tracing_log_data)

    assert (
        len(pre_tracing_log_matches) == 0
    ), f"Expected no log-instrument traces in logs before enabling TRACE, but found: {pre_tracing_log_matches}"

    post_tracing_log_data = vm.log_data

    assert TRACE_LEVEL_HINT in post_tracing_log_data, "Expected TRACE level logs in output"

    post_tracing_log_matches = re.findall(MARKER_REGEX, post_tracing_log_data)

    assert (
        len(post_tracing_log_matches) > 0
    ), f"Expected to find log-instrument traces in logs, but found none. Log data: {post_tracing_log_data[:1000]}..."

    entry_traces = [match for match in post_tracing_log_matches if ">>" in match]
    exit_traces = [match for match in post_tracing_log_matches if "<<" in match]

    assert len(entry_traces) > 0, "Expected to find function entry traces (>>)"
    assert len(exit_traces) > 0, "Expected to find function exit traces (<<)"

    meaningful_keywords = ["vmm", "request", "response"]

    # Ensure that each of the meaningful keywords is present in at least one trace
    # match from the post-tracing logs.
    assert all(
        any(keyword.lower() in trace.lower() for trace in post_tracing_log_matches)
        for keyword in meaningful_keywords
    ), (
        f"Expected to find traces from meaningful keywords {meaningful_keywords}, "
        f"but traces were: {post_tracing_log_matches[:10]}..."
    )


Review comment (bug):
This time trace logs disappeared (see [test failure](https://buildkite.com/firecracker/firecracker-pr/builds/14968#019a5314-3904-46e7-99ad-05a9b7590475/58-4364)). Is it related somehow with the change from `Trace` to `Info` in the `spawn()`?

Code after:

    pre_tracing_log_data = vm.log_data

    # Ensure TRACE logs are being captured
    logger_config = {
        "level": "Trace",
        "show_level": True,
        "show_log_origin": True,
    }
    _ = vm.api.logger.put(**logger_config)

    # Another API call after enabling TRACE
    _ = vm.api.describe.get()

    assert (
        TRACE_LEVEL_HINT not in pre_tracing_log_data
    ), "TRACE level logs were found before setting log level to TRACE. "

    pre_tracing_log_matches = re.findall(MARKER_REGEX, pre_tracing_log_data)

    assert (
        len(pre_tracing_log_matches) == 0
    ), f"Expected no log-instrument traces in logs before enabling TRACE, but found: {pre_tracing_log_matches}"

    post_tracing_log_data = vm.log_data

    assert (
        TRACE_LEVEL_HINT in post_tracing_log_data
    ), "Expected TRACE level logs in output"

    post_tracing_log_matches = re.findall(MARKER_REGEX, post_tracing_log_data)

    assert (
        len(post_tracing_log_matches) > 0
    ), f"Expected to find log-instrument traces in logs, but found none. Log data: {post_tracing_log_data[:1000]}..."

    entry_traces = [match for match in post_tracing_log_matches if ">>" in match]
    exit_traces = [match for match in post_tracing_log_matches if "<<" in match]

    assert len(entry_traces) > 0, "Expected to find function entry traces (>>)"
    assert len(exit_traces) > 0, "Expected to find function exit traces (<<)"

    meaningful_keywords = ["vmm", "request", "response"]

    # Ensure that each of the meaningful keywords is present in at least one trace
    # match from the post-tracing logs.
    assert all(
        any(keyword.lower() in trace.lower() for trace in post_tracing_log_matches)
        for keyword in meaningful_keywords
    ), (
        f"Expected to find traces from meaningful keywords {meaningful_keywords}, "