Skip to content

refactor: replace tracing-log with native tracing macros for guest log forwarding#1500

Open
cshung wants to merge 1 commit into
hyperlight-dev:mainfrom
cshung:tracing-consolidation
Open

refactor: replace tracing-log with native tracing macros for guest log forwarding#1500
cshung wants to merge 1 commit into
hyperlight-dev:mainfrom
cshung:tracing-consolidation

Conversation

@cshung
Copy link
Copy Markdown

@cshung cshung commented Jun 2, 2026

Summary

Remove the tracing-log dependency from hyperlight-host and replace the format_trace/log::Record approach in outb_log with direct tracing event macros (error!, warn!, info!, debug!, trace!).

This consolidates guest log emission on the tracing crate, while preserving backward compatibility for consumers using only the log crate (via tracing's built-in log feature).

Changes

  • src/hyperlight_host/Cargo.toml: Removed tracing-log dependency
  • src/hyperlight_host/src/sandbox/outb.rs: Replaced format_trace/log::Record with native tracing macros matched on LogLevel
  • src/hyperlight_host/tests/integration_test.rs: Switched use log::{error, trace} to use tracing::{error, trace}
  • src/tests/rust_guests/simpleguest/src/main.rs: Switched log::info! to tracing::info! (kept log import for backward compat test)

Testing

  • All unit tests pass (debug + release)
  • All integration tests pass (debug + release)
  • Clippy clean (debug + release)
  • test_log_outb_log verifies backward compatibility with log-only consumers
  • test_trace_outb_log verifies tracing subscriber path

Closes #1028

…g forwarding

Remove the tracing-log dependency from hyperlight-host and replace the
format_trace/log::Record approach in outb_log with direct tracing event
macros (error!, warn!, info!, debug!, trace!). This consolidates guest
log emission on the tracing crate, while preserving backward
compatibility for consumers using only the log crate (via tracing's
built-in log feature).

Closes hyperlight-dev#1028

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: cshung <3410332+cshung@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 2, 2026 20:49
Copy link
Copy Markdown
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

Note

Copilot was unable to run its full agentic suite in this review.

This PR migrates guest/host logging paths away from log records + tracing-log formatting and toward emitting tracing events directly, while updating tests and dependencies accordingly.

Changes:

  • Emit guest log messages in outb_log as structured tracing::* events instead of formatting a log::Record via tracing_log::format_trace.
  • Replace some log macro usage/imports with tracing in guest and integration tests.
  • Remove the tracing-log dependency from hyperlight_host.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.

File Description
src/tests/rust_guests/simpleguest/src/main.rs Adjust imports and switch one traced log site to tracing::info!.
src/hyperlight_host/tests/integration_test.rs Use tracing::{error, trace} instead of log::{error, trace}.
src/hyperlight_host/src/sandbox/outb.rs Rework outb_log to emit tracing events with guest metadata as fields; update tests accordingly.
src/hyperlight_host/Cargo.toml Drop tracing-log dependency.

Comment on lines +69 to +83
// Emit guest log data as a tracing event with structured fields.
//
// This function is *not* considered part of `tracing`'s public API, and has no
// stability guarantees. If you use it, and it breaks or disappears entirely,
// don't say we didn't warn you.

let should_trace = tracing_core::dispatcher::has_been_set();
let source_file = Some(log_data.source_file.as_str());
let line = Some(log_data.line);
let source = Some(log_data.source.as_str());

// See https://github.com/rust-lang/rust/issues/42253 for the reason this has to be done this way

if should_trace {
// Create a tracing event for the GuestLogData
// Ideally we would create tracing metadata based on the Guest Log Data
// but tracing derives the metadata at compile time
// see https://github.com/tokio-rs/tracing/issues/2419
// so we leave it up to the subscriber to figure out that there are logging fields present with this data
format_trace(
&Record::builder()
.args(format_args!("{}", log_data.message))
.level(record_level)
.target("hyperlight_guest")
.file(source_file)
.line(line)
.module_path(source)
.build(),
)
.map_err(|e| HandleOutbError::TraceFormat(e.to_string()))?;
} else {
// Create a log record for the GuestLogData
log::logger().log(
&Record::builder()
.args(format_args!("{}", log_data.message))
.level(record_level)
.target("hyperlight_guest")
.file(Some(&log_data.source_file))
.line(Some(log_data.line))
.module_path(Some(&log_data.source))
.build(),
);
// We match on the level at runtime because tracing macros determine their
// level at compile time. Guest file/line/module are passed as structured
// fields (rather than tracing metadata) because they originate from the
// guest, not from this call site.
//
// Consumers using a `log` logger (without a tracing subscriber) still
// receive these events thanks to the `tracing` crate's `log` feature,
// which forwards tracing events to the `log` facade when no subscriber
// is set.
let source_file = log_data.source_file.as_str();
let line = log_data.line;
let source = log_data.source.as_str();
let message = log_data.message.as_str();
Comment on lines 277 to 279
#[test]
#[ignore]
fn test_log_outb_log() {
@ludfjig ludfjig added the kind/refactor For PRs that restructure or remove code without adding new functionality. label Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/refactor For PRs that restructure or remove code without adding new functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use tracing crate instead of log to create logs

3 participants