Skip to content
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions src/hyperlight_common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ workspace = true
[dependencies]
flatbuffers = { version = "25.9.23", default-features = false }
anyhow = { version = "1.0.100", default-features = false }
log = "0.4.28"
tracing = { version = "0.1.41", optional = true }
tracing = { version = "0.1.41" }
arbitrary = {version = "1.4.2", optional = true, features = ["derive"]}
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

default = []
fuzzing = ["dep:arbitrary"]
trace_guest = []
mem_profile = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use alloc::vec::Vec;

use anyhow::{Error, Result, bail};
use flatbuffers::{FlatBufferBuilder, WIPOffset, size_prefixed_root};
#[cfg(feature = "tracing")]
use tracing::{Span, instrument};

use super::function_types::{ParameterValue, ReturnType};
Expand Down Expand Up @@ -53,7 +52,7 @@ pub struct FunctionCall {
}

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)

pub fn new(
function_name: String,
parameters: Option<Vec<ParameterValue>>,
Expand Down Expand Up @@ -214,7 +213,7 @@ impl FunctionCall {
}
}

#[cfg_attr(feature = "tracing", instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace"))]
#[instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace")]
pub fn validate_guest_function_call_buffer(function_call_buffer: &[u8]) -> Result<()> {
let guest_function_call_fb = size_prefixed_root::<FbFunctionCall>(function_call_buffer)
.map_err(|e| anyhow::anyhow!("Error reading function call buffer: {:?}", e))?;
Expand All @@ -226,7 +225,7 @@ pub fn validate_guest_function_call_buffer(function_call_buffer: &[u8]) -> Resul
}
}

#[cfg_attr(feature = "tracing", instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace"))]
#[instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace")]
pub fn validate_host_function_call_buffer(function_call_buffer: &[u8]) -> Result<()> {
let host_function_call_fb = size_prefixed_root::<FbFunctionCall>(function_call_buffer)
.map_err(|e| anyhow::anyhow!("Error reading function call buffer: {:?}", e))?;
Expand All @@ -240,7 +239,7 @@ pub fn validate_host_function_call_buffer(function_call_buffer: &[u8]) -> Result

impl TryFrom<&[u8]> for FunctionCall {
type Error = Error;
#[cfg_attr(feature = "tracing", instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace"))]
#[instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace")]
fn try_from(value: &[u8]) -> Result<Self> {
let function_call_fb = size_prefixed_root::<FbFunctionCall>(value)
.map_err(|e| anyhow::anyhow!("Error reading function call buffer: {:?}", e))?;
Expand Down
55 changes: 27 additions & 28 deletions src/hyperlight_common/src/flatbuffer_wrappers/function_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use alloc::vec::Vec;

use anyhow::{Error, Result, anyhow, bail};
use flatbuffers::size_prefixed_root;
#[cfg(feature = "tracing")]
use tracing::{Span, instrument};

use super::guest_error::GuestError;
Expand Down Expand Up @@ -284,7 +283,7 @@ pub enum ReturnType {
}

impl From<&ParameterValue> for ParameterType {
#[cfg_attr(feature = "tracing", instrument(skip_all, parent = Span::current(), level= "Trace"))]
#[instrument(skip_all, parent = Span::current(), level= "Trace")]
fn from(value: &ParameterValue) -> Self {
match *value {
ParameterValue::Int(_) => ParameterType::Int,
Expand All @@ -303,7 +302,7 @@ impl From<&ParameterValue> for ParameterType {
impl TryFrom<Parameter<'_>> for ParameterValue {
type Error = Error;

#[cfg_attr(feature = "tracing", instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace"))]
#[instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace")]
fn try_from(param: Parameter<'_>) -> Result<Self> {
let value = param.value_type();
let result = match value {
Expand Down Expand Up @@ -343,7 +342,7 @@ impl TryFrom<Parameter<'_>> for ParameterValue {
}

impl From<ParameterType> for FbParameterType {
#[cfg_attr(feature = "tracing", instrument(skip_all, parent = Span::current(), level= "Trace"))]
#[instrument(skip_all, parent = Span::current(), level= "Trace")]
fn from(value: ParameterType) -> Self {
match value {
ParameterType::Int => FbParameterType::hlint,
Expand All @@ -360,7 +359,7 @@ impl From<ParameterType> for FbParameterType {
}

impl From<ReturnType> for FbReturnType {
#[cfg_attr(feature = "tracing", instrument(skip_all, parent = Span::current(), level= "Trace"))]
#[instrument(skip_all, parent = Span::current(), level= "Trace")]
fn from(value: ReturnType) -> Self {
match value {
ReturnType::Int => FbReturnType::hlint,
Expand All @@ -379,7 +378,7 @@ impl From<ReturnType> for FbReturnType {

impl TryFrom<FbParameterType> for ParameterType {
type Error = Error;
#[cfg_attr(feature = "tracing", instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace"))]
#[instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace")]
fn try_from(value: FbParameterType) -> Result<Self> {
match value {
FbParameterType::hlint => Ok(ParameterType::Int),
Expand All @@ -400,7 +399,7 @@ impl TryFrom<FbParameterType> for ParameterType {

impl TryFrom<FbReturnType> for ReturnType {
type Error = Error;
#[cfg_attr(feature = "tracing", instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace"))]
#[instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace")]
fn try_from(value: FbReturnType) -> Result<Self> {
match value {
FbReturnType::hlint => Ok(ReturnType::Int),
Expand All @@ -422,7 +421,7 @@ impl TryFrom<FbReturnType> for ReturnType {

impl TryFrom<ParameterValue> for i32 {
type Error = Error;
#[cfg_attr(feature = "tracing", instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace"))]
#[instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace")]
fn try_from(value: ParameterValue) -> Result<Self> {
match value {
ParameterValue::Int(v) => Ok(v),
Expand All @@ -435,7 +434,7 @@ impl TryFrom<ParameterValue> for i32 {

impl TryFrom<ParameterValue> for u32 {
type Error = Error;
#[cfg_attr(feature = "tracing", instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace"))]
#[instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace")]
fn try_from(value: ParameterValue) -> Result<Self> {
match value {
ParameterValue::UInt(v) => Ok(v),
Expand All @@ -448,7 +447,7 @@ impl TryFrom<ParameterValue> for u32 {

impl TryFrom<ParameterValue> for i64 {
type Error = Error;
#[cfg_attr(feature = "tracing", instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace"))]
#[instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace")]
fn try_from(value: ParameterValue) -> Result<Self> {
match value {
ParameterValue::Long(v) => Ok(v),
Expand All @@ -461,7 +460,7 @@ impl TryFrom<ParameterValue> for i64 {

impl TryFrom<ParameterValue> for u64 {
type Error = Error;
#[cfg_attr(feature = "tracing", instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace"))]
#[instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace")]
fn try_from(value: ParameterValue) -> Result<Self> {
match value {
ParameterValue::ULong(v) => Ok(v),
Expand All @@ -474,7 +473,7 @@ impl TryFrom<ParameterValue> for u64 {

impl TryFrom<ParameterValue> for f32 {
type Error = Error;
#[cfg_attr(feature = "tracing", instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace"))]
#[instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace")]
fn try_from(value: ParameterValue) -> Result<Self> {
match value {
ParameterValue::Float(v) => Ok(v),
Expand All @@ -487,7 +486,7 @@ impl TryFrom<ParameterValue> for f32 {

impl TryFrom<ParameterValue> for f64 {
type Error = Error;
#[cfg_attr(feature = "tracing", instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace"))]
#[instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace")]
fn try_from(value: ParameterValue) -> Result<Self> {
match value {
ParameterValue::Double(v) => Ok(v),
Expand All @@ -500,7 +499,7 @@ impl TryFrom<ParameterValue> for f64 {

impl TryFrom<ParameterValue> for String {
type Error = Error;
#[cfg_attr(feature = "tracing", instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace"))]
#[instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace")]
fn try_from(value: ParameterValue) -> Result<Self> {
match value {
ParameterValue::String(v) => Ok(v),
Expand All @@ -513,7 +512,7 @@ impl TryFrom<ParameterValue> for String {

impl TryFrom<ParameterValue> for bool {
type Error = Error;
#[cfg_attr(feature = "tracing", instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace"))]
#[instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace")]
fn try_from(value: ParameterValue) -> Result<Self> {
match value {
ParameterValue::Bool(v) => Ok(v),
Expand All @@ -526,7 +525,7 @@ impl TryFrom<ParameterValue> for bool {

impl TryFrom<ParameterValue> for Vec<u8> {
type Error = Error;
#[cfg_attr(feature = "tracing", instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace"))]
#[instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace")]
fn try_from(value: ParameterValue) -> Result<Self> {
match value {
ParameterValue::VecBytes(v) => Ok(v),
Expand All @@ -539,7 +538,7 @@ impl TryFrom<ParameterValue> for Vec<u8> {

impl TryFrom<ReturnValue> for i32 {
type Error = Error;
#[cfg_attr(feature = "tracing", instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace"))]
#[instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace")]
fn try_from(value: ReturnValue) -> Result<Self> {
match value {
ReturnValue::Int(v) => Ok(v),
Expand All @@ -552,7 +551,7 @@ impl TryFrom<ReturnValue> for i32 {

impl TryFrom<ReturnValue> for u32 {
type Error = Error;
#[cfg_attr(feature = "tracing", instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace"))]
#[instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace")]
fn try_from(value: ReturnValue) -> Result<Self> {
match value {
ReturnValue::UInt(v) => Ok(v),
Expand All @@ -565,7 +564,7 @@ impl TryFrom<ReturnValue> for u32 {

impl TryFrom<ReturnValue> for i64 {
type Error = Error;
#[cfg_attr(feature = "tracing", instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace"))]
#[instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace")]
fn try_from(value: ReturnValue) -> Result<Self> {
match value {
ReturnValue::Long(v) => Ok(v),
Expand All @@ -578,7 +577,7 @@ impl TryFrom<ReturnValue> for i64 {

impl TryFrom<ReturnValue> for u64 {
type Error = Error;
#[cfg_attr(feature = "tracing", instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace"))]
#[instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace")]
fn try_from(value: ReturnValue) -> Result<Self> {
match value {
ReturnValue::ULong(v) => Ok(v),
Expand All @@ -591,7 +590,7 @@ impl TryFrom<ReturnValue> for u64 {

impl TryFrom<ReturnValue> for f32 {
type Error = Error;
#[cfg_attr(feature = "tracing", instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace"))]
#[instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace")]
fn try_from(value: ReturnValue) -> Result<Self> {
match value {
ReturnValue::Float(v) => Ok(v),
Expand All @@ -604,7 +603,7 @@ impl TryFrom<ReturnValue> for f32 {

impl TryFrom<ReturnValue> for f64 {
type Error = Error;
#[cfg_attr(feature = "tracing", instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace"))]
#[instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace")]
fn try_from(value: ReturnValue) -> Result<Self> {
match value {
ReturnValue::Double(v) => Ok(v),
Expand All @@ -617,7 +616,7 @@ impl TryFrom<ReturnValue> for f64 {

impl TryFrom<ReturnValue> for String {
type Error = Error;
#[cfg_attr(feature = "tracing", instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace"))]
#[instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace")]
fn try_from(value: ReturnValue) -> Result<Self> {
match value {
ReturnValue::String(v) => Ok(v),
Expand All @@ -630,7 +629,7 @@ impl TryFrom<ReturnValue> for String {

impl TryFrom<ReturnValue> for bool {
type Error = Error;
#[cfg_attr(feature = "tracing", instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace"))]
#[instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace")]
fn try_from(value: ReturnValue) -> Result<Self> {
match value {
ReturnValue::Bool(v) => Ok(v),
Expand All @@ -643,7 +642,7 @@ impl TryFrom<ReturnValue> for bool {

impl TryFrom<ReturnValue> for Vec<u8> {
type Error = Error;
#[cfg_attr(feature = "tracing", instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace"))]
#[instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace")]
fn try_from(value: ReturnValue) -> Result<Self> {
match value {
ReturnValue::VecBytes(v) => Ok(v),
Expand All @@ -656,7 +655,7 @@ impl TryFrom<ReturnValue> for Vec<u8> {

impl TryFrom<ReturnValue> for () {
type Error = Error;
#[cfg_attr(feature = "tracing", instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace"))]
#[instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace")]
fn try_from(value: ReturnValue) -> Result<Self> {
match value {
ReturnValue::Void(()) => Ok(()),
Expand All @@ -669,7 +668,7 @@ impl TryFrom<ReturnValue> for () {

impl TryFrom<ReturnValueBox<'_>> for ReturnValue {
type Error = Error;
#[cfg_attr(feature = "tracing", instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace"))]
#[instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace")]
fn try_from(return_value_box: ReturnValueBox<'_>) -> Result<Self> {
match return_value_box.value_type() {
FbReturnValue::hlint => {
Expand Down Expand Up @@ -740,7 +739,7 @@ impl TryFrom<ReturnValueBox<'_>> for ReturnValue {

impl TryFrom<&ReturnValue> for Vec<u8> {
type Error = Error;
#[cfg_attr(feature = "tracing", instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace"))]
#[instrument(err(Debug), skip_all, parent = Span::current(), level= "Trace")]
fn try_from(value: &ReturnValue) -> Result<Vec<u8>> {
let mut builder = flatbuffers::FlatBufferBuilder::new();
let result_bytes = match value {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ extern crate flatbuffers;

use alloc::string::{String, ToString};

#[cfg(feature = "tracing")]
use tracing::{Span, instrument};

use crate::flatbuffers::hyperlight::generated::ErrorCode as FbErrorCode;
Expand Down Expand Up @@ -189,14 +188,14 @@ pub struct GuestError {
}

impl GuestError {
#[cfg_attr(feature = "tracing", instrument(skip_all, parent = Span::current(), level= "Trace"))]
#[instrument(skip_all, parent = Span::current(), level= "Trace")]
pub fn new(code: ErrorCode, message: String) -> Self {
Self { code, message }
}
}

impl Default for GuestError {
#[cfg_attr(feature = "tracing", instrument(parent = Span::current(), level= "Trace"))]
#[instrument(parent = Span::current(), level= "Trace")]
fn default() -> Self {
Self {
code: ErrorCode::NoError,
Expand Down
Loading