Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 25, 2025

Plan: Replace log crate with tracing - ✅ COMPLETE

  • Explore the repository structure and understand current logging usage
  • Identify all files using the log crate
  • Replace log imports with tracing equivalents in host source files:
    • hyperlight_common - Updated to use tracing::Level with log compatibility
    • hyperlight_host - All log macros replaced with tracing
    • hyperlight_component_util - Updated to use tracing::debug
    • hyperlight_guest_bin - Only guest_logger.rs uses tracing::log internally
    • ✅ hyperlight_guest_capi - Keeps log dependency (unchanged)
    • ✅ hyperlight_testing - Keeps log for test bridge (intentional - correct)
    • ✅ Test guests - Keep log dependency (unchanged)
  • Update Cargo.toml dependencies for host crates
  • Update logging macro calls and implementations
  • Handle type conversions (Level, LevelFilter) including tracing::log::Level
  • Update internal macros
  • Fix test code compatibility
  • Remove redundant parent = Span::current() from instrument attributes (it's the default)
  • Test the changes:
    • Build hyperlight-host ✓
    • Build hyperlight-common ✓
    • Build hyperlight-guest-bin ✓
    • Build all guests ✓
    • Run tests ✓
  • Run fmt ✓

Summary of Changes

Host code - completely replaced log with tracing:

  • The log crate dependency is removed from host crates (hyperlight_host, hyperlight_common, hyperlight_component_util)
  • log::error!tracing::error!
  • log::warn!tracing::warn!
  • log::info!tracing::info!
  • log::debug!tracing::debug!
  • log::trace!tracing::trace!
  • log::Leveltracing::Level with correct constants (TRACE, DEBUG, INFO, WARN, ERROR)
  • Removed redundant parent = Span::current() from all instrument attributes

Guest code - minimal changes:

  • hyperlight_guest_bin/src/guest_logger.rs internally uses tracing::log types for the logger implementation
  • Added conversion from tracing::log::Level to LogLevel in hyperlight_common to support the guest logger
  • Guest crates (hyperlight_guest_capi, test guests) retain their original log dependencies

Cargo.toml updates:

  • hyperlight_common: Uses tracing with attributes and log features (removed log dependency)
  • hyperlight_host: Removed log dependency, uses tracing
  • hyperlight_component_util: Replaced log with tracing
  • hyperlight_guest_bin: Keeps log dependency for guest code
  • hyperlight_guest_capi: Keeps log dependency (unchanged)
  • Test guests: Keep log dependencies (unchanged)

The changes maintain full backward compatibility. Host code uses pure tracing, while guest code continues to use log with minimal internal use of tracing::log for compatibility in the logger implementation. Embedders can use either log or tracing as consumers, and the logging will work correctly in both cases.

Original prompt

This section details on the original issue you should resolve

<issue_title>Use tracing crate instead of log to create logs</issue_title>
<issue_description>We are currently using both the tracing and log crate to emit logs in Hyperlight. We should only use tracing that extends log's functionality and adds more features.

Furthermore, some examples would be nice to demonstrate the use of the hyperlight crate as a dependency and show how the logs can be retrieved regardless of which crate (log or tracing) the example uses.</issue_description>

<agent_instructions>Make sure the log crate is not used any more.
Furthermore, ensure the behaviour is similar when the embedder uses either log or tracing.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Use tracing crate instead of log for logging Replace log crate with tracing in host code Nov 25, 2025
Copilot AI requested a review from dblnz November 25, 2025 19:55
spin = "0.10.0"

[features]
default = ["tracing"]
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure if we want to remove the #[instrument] condition from hyperlight-common. But, considering the hyperlight guests can now use the same tracing crate as the host, I think this would be fine


impl FunctionCall {
#[cfg_attr(feature = "tracing", instrument(skip_all, parent = Span::current(), level= "Trace"))]
#[instrument(skip_all, parent = Span::current(), level= "Trace")]
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can remove parent = Span::current() because it is the default and it is redundant

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed parent = Span::current() from all 49 occurrences in flatbuffer_wrappers files and removed the now-unused Span imports. (f4dd6d2)

@jsturtevant
Copy link
Contributor

@copilot look at the suggestions

Copy link
Contributor

@dblnz dblnz left a comment

Choose a reason for hiding this comment

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

hyperlight_guest_bin/src/guest_logger.rs needs to also use the tracing crate and not log crate.
Update the other crates to use tracing instead of log where it's the case

anyhow = { version = "1.0.100", default-features = false }
log = "0.4.28"
tracing = { version = "0.1.41", optional = true }
tracing = { version = "0.1.41" }
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
tracing = { version = "0.1.41" }
tracing = { version = "0.1.41", default-features = false, features = [ "attributes" ] }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Applied the suggestion and also added the log feature to maintain compatibility: tracing = { version = "0.1.41", default-features = false, features = [ "attributes", "log" ] } (d020eab)

@dblnz
Copy link
Contributor

dblnz commented Dec 9, 2025

@copilot take that suggestions and comments into consideration

Copy link
Contributor Author

Copilot AI commented Dec 9, 2025

hyperlight_guest_bin/src/guest_logger.rs needs to also use the tracing crate and not log crate.
Update the other crates to use tracing instead of log where it's the case

Updated all guest code to use tracing with the log feature instead of direct log dependency:

  • hyperlight_guest_bin/src/guest_logger.rs now uses tracing::log
  • hyperlight_guest_capi now uses tracing::log with a C-compatible Level enum wrapper
  • Test guests like simpleguest updated to use tracing::log
  • All Cargo.toml files updated to remove log dependency and use tracing with log feature

The log crate is no longer a direct dependency anywhere. (d020eab)

Copilot AI changed the title Replace log crate with tracing in host code Replace log crate with tracing in all code Dec 9, 2025
Copilot AI requested a review from dblnz December 9, 2025 10:09
@dblnz
Copy link
Contributor

dblnz commented Dec 9, 2025

@copilot Drop all the changes for the guest crates except for the on in guest_logger.rs where the record.level().into() fails because the new tracing::LogLevel cannot be correctly converted

Copy link
Contributor Author

Copilot AI commented Dec 9, 2025

@copilot Drop all the changes for the guest crates except for the on in guest_logger.rs where the record.level().into() fails because the new tracing::LogLevel cannot be correctly converted

Reverted all guest crate changes except guest_logger.rs. The logger now uses tracing::log types and the conversion from tracing::log::Level to LogLevel is maintained in hyperlight_common. Guest crates keep their original log dependencies. (d435175)

Copilot AI changed the title Replace log crate with tracing in all code Replace log crate with tracing in host code Dec 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use tracing crate instead of log to create logs

3 participants