Skip to content

Comments

Fix guest tracing filter#977

Open
dblnz wants to merge 4 commits intohyperlight-dev:mainfrom
dblnz:fix-tracing-filter
Open

Fix guest tracing filter#977
dblnz wants to merge 4 commits intohyperlight-dev:mainfrom
dblnz:fix-tracing-filter

Conversation

@dblnz
Copy link
Contributor

@dblnz dblnz commented Oct 24, 2025

This closes #990.
Currently, when tracing guests, the max log level parameter provided to the guest is not used to filter out traces.

This PR adds the filtering capability for the guest tracing and also modifies some of the trace levels in the guest.
For that to work, a change in the integration_tests.rs was necessary to update the number of expected logs in log_message test

@dblnz dblnz added the kind/enhancement For PRs adding features, improving functionality, docs, tests, etc. label Oct 24, 2025
@dblnz dblnz self-assigned this Oct 24, 2025
@dblnz dblnz force-pushed the fix-tracing-filter branch from 489acde to 7ff7b03 Compare October 24, 2025 15:19
@dblnz dblnz force-pushed the fix-tracing-filter branch from 7ff7b03 to 58caf0d Compare January 23, 2026 12:30
@dblnz dblnz marked this pull request as ready for review January 23, 2026 12:31
ludfjig
ludfjig previously approved these changes Jan 23, 2026
Copy link
Contributor

@ludfjig ludfjig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but it would be nice if it was possible to remove all uses of tracing::log::LeverFilter and log::Levelfilter for tracing_core::LevelFilter/tracing::LevelFilter instead

@jsturtevant
Copy link
Contributor

@dblnz would you like to get this into the next release (we have it scheduled for next week (Feb 25th)

@dblnz
Copy link
Contributor Author

dblnz commented Feb 18, 2026

@dblnz would you like to get this into the next release (we have it scheduled for next week (Feb 25th)

Yes, I'm rebasing it to include it in the release

@dblnz dblnz force-pushed the fix-tracing-filter branch 5 times, most recently from 6e47f8f to 72aaf11 Compare February 19, 2026 14:13
jsturtevant
jsturtevant previously approved these changes Feb 20, 2026
ludfjig
ludfjig previously approved these changes Feb 20, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes issue #990 by implementing proper filtering of guest tracing spans and events based on the max_log_level parameter. Previously, even though the log level was correctly received by guests, only logs were filtered while tracing spans and events were not.

Changes:

  • Introduced a new GuestLogFilter enum to unify log level conversions between log::LevelFilter, tracing_core::LevelFilter, and u64 values passed across the host-guest boundary
  • Implemented filtering in the GuestSubscriber::enabled() method to properly filter tracing spans and events based on the maximum log level
  • Updated trace span levels from Trace to Info for infrastructure calls (halt, dispatch_function, call_guest_function, call_host_function) to ensure they are visible at appropriate log levels and updated test expectations accordingly

Reviewed changes

Copilot reviewed 18 out of 22 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/hyperlight_common/src/log_level.rs New file introducing GuestLogFilter enum with conversions to/from log::LevelFilter, tracing_core::LevelFilter, and u64
src/hyperlight_common/src/lib.rs Adds log_level module export
src/hyperlight_common/Cargo.toml Adds tracing-core dependency
src/hyperlight_guest_tracing/src/subscriber.rs Adds max_log_level field and implements filtering in enabled() method
src/hyperlight_guest_tracing/src/lib.rs Updates init_guest_tracing to accept LevelFilter parameter
src/hyperlight_guest_tracing/Cargo.toml Adds "log" feature to tracing dependency for log/tracing interop
src/hyperlight_guest_bin/src/lib.rs Updates to use GuestLogFilter for initialization
src/hyperlight_guest_bin/src/guest_logger.rs Minor parameter rename for clarity
src/hyperlight_guest_bin/src/guest_function/call.rs Updates trace levels from Trace to Info and removes explicit parent span references
src/hyperlight_host/src/hypervisor/mod.rs Removes old get_max_log_level function
src/hyperlight_host/src/hypervisor/hyperlight_vm.rs Adds new get_max_log_level_filter and get_guest_log_filter functions with proper conversions
src/hyperlight_host/src/sandbox/uninitialized.rs Updates imports to use tracing_core::LevelFilter
src/hyperlight_host/src/sandbox/trace/context.rs Updates span levels from trace to info
src/hyperlight_host/tests/integration_test.rs Updates test expectations to account for new info-level trace logs and converts to use tracing_core::LevelFilter
src/hyperlight_guest/src/exit.rs Updates halt span level from Trace to Info
src/hyperlight_guest/src/guest_handle/io.rs Removes explicit parent span reference
src/hyperlight_guest/src/guest_handle/host_comm.rs Adds instrumentation and updates trace levels
src/tests/rust_guests/simpleguest/src/main.rs CRITICAL BUG: Incorrect conversion logic in LogMessage function
Cargo.lock files Updates dependency locks for tracing-core additions

@dblnz dblnz dismissed stale reviews from ludfjig and jsturtevant via 214c2de February 23, 2026 11:13
@dblnz dblnz force-pushed the fix-tracing-filter branch from 72aaf11 to 214c2de Compare February 23, 2026 11:13
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 17 out of 21 changed files in this pull request and generated 3 comments.

@dblnz dblnz force-pushed the fix-tracing-filter branch from 214c2de to f4c4af9 Compare February 23, 2026 11:48
ludfjig
ludfjig previously approved these changes Feb 23, 2026
Copy link
Contributor

@ludfjig ludfjig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

use crate::sandbox::uninitialized::SandboxRuntimeConfig;

/// Get the logging level filter to pass to the guest entrypoint
fn get_max_log_level_filter() -> LevelFilter {
Copy link
Contributor

@ludfjig ludfjig Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is not related to this PR, but this code could be simplified. AI came up with this but I'm sure it can be further tweaked (not blocking, feel free to ignore if you wish)

fn get_max_log_level_filter() -> LevelFilter {
    let rust_log = std::env::var("RUST_LOG").unwrap_or_default();

    let level = rust_log
        .split(',')
        .find_map(|entry| {
            entry
                .strip_prefix("hyperlight_guest=")
                .or_else(|| entry.strip_prefix("hyperlight_host="))
                .or_else(|| {
                    // Fallback: global log level (no '=' present)
                    if !entry.contains('=') {
                        Some(entry)
                    } else {
                        None
                    }
                })
        })
        .unwrap_or("");

    tracing::info!("Determined guest log level: {}", level);

    LevelFilter::from_str(level).unwrap_or(LevelFilter::ERROR)
}

jsturtevant
jsturtevant previously approved these changes Feb 23, 2026
…arent

- To make the codebase more readable, remove the `parent` argument from
  the `#[instrument]` attribute.

Signed-off-by: Doru Blânzeanu <dblnz@pm.me>
- The `max_log_level` argument provided to the guest function is
  now used to filter traces also

Signed-off-by: Doru Blânzeanu <dblnz@pm.me>
… and logging

- Adds a `GuestLogFilter` enum that is used as an intermediary type
  between the `u64` used as a register to call the guest entrypoint and
  the `log::LogFilter` or `tracing_core::LogFilter`.
- Adds unit tests for the `GuestLogFilter`.

Signed-off-by: Doru Blânzeanu <dblnz@pm.me>
- Add more comments and tests to verify the new logic works as expected

Signed-off-by: Doru Blânzeanu <dblnz@pm.me>
@dblnz dblnz dismissed stale reviews from jsturtevant and ludfjig via b243e36 February 24, 2026 11:05
@dblnz dblnz force-pushed the fix-tracing-filter branch from f4c4af9 to b243e36 Compare February 24, 2026 11:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/enhancement For PRs adding features, improving functionality, docs, tests, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix guest tracing filtering

3 participants