You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor: replace tracing-log with native tracing macros for guest log forwarding (#1500)
* refactor: replace tracing-log with native tracing macros for guest log 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#1028
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: cshung <3410332+cshung@users.noreply.github.com>
* docs: update observability docs to reflect tracing-log removal
Remove references to tracing-log crate and LogTracer from the
metrics/logs/traces documentation. Updated to reflect that Hyperlight
now uses the tracing crate's built-in log feature for forwarding events
to log consumers.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: cshung <3410332+cshung@users.noreply.github.com>
* refactor: rename guest log fields per review feedback
Rename tracing event fields from guest_source_file to guest_file and
keep guest_line and guest_module consistent with the shorter naming
convention requested in review.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: cshung <3410332+cshung@users.noreply.github.com>
---------
Signed-off-by: cshung <3410332+cshung@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy file name to clipboardExpand all lines: docs/hyperlight-metrics-logs-and-traces.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@
3
3
Hyperlight provides the following observability features:
4
4
5
5
*[Metrics](#metrics) are provided using the [metrics](https://docs.rs/metrics/latest/metrics/index.html) crate, which is a lightweight metrics facade.
6
-
*[Logs](#logs) are provided using the Rust [log crate](https://docs.rs/log/0.4.6/log/), and can be consumed by any Rust logger implementation, including LogTracer which can be used to emit log records as tracing events.
6
+
*[Logs](#logs) are provided using the Rust [tracing crate](https://docs.rs/tracing/latest/tracing/) with the `log` feature enabled, allowing logs to be consumed by any Rust logger implementation compatible with the [log crate](https://docs.rs/log/latest/log/).
7
7
*[Tracing](#tracing) is provided using the Rust [tracing crate](https://docs.rs/tracing/0.1.37/tracing/), and can be consumed by any Rust tracing implementation. In addition, the [log feature](https://docs.rs/tracing/latest/tracing/#crate-feature-flags) is enabled which means that should a hyperlight host application not want to consume tracing events, you can still consume them as logs.
8
8
9
9
## Metrics
@@ -30,7 +30,7 @@ We might consider enabling these metrics by default in the future.
30
30
31
31
## Logs
32
32
33
-
Hyperlight provides logs using the Rust [log crate](https://docs.rs/log/0.4.6/log/), and can be consumed by any Rust logger implementation, including LogTracer which can be used to emit log records as tracing events(see below for more details). To consume logs, the host application must provide a logger implementation either by using the `set_logger` function directly or using a logger implementation that is compatible with the log crate.
33
+
Hyperlight provides logs using the Rust [tracing crate](https://docs.rs/tracing/latest/tracing/) with the [`log` feature](https://docs.rs/tracing/latest/tracing/#crate-feature-flags) enabled. This means log events can be consumed by any Rust logger implementation compatible with the [log crate](https://docs.rs/log/latest/log/). To consume logs, the host application must provide a logger implementation either by using the `set_logger` function directly or using a logger implementation that is compatible with the log crate.
34
34
35
35
For an example that uses the `env_logger` crate, see the [examples/logging](../src/hyperlight_host/examples/logging) directory. By default, the `env_logger` crate will only log messages at the `error` level or higher. To see all log messages, set the `RUST_LOG` environment variable to `debug`.
36
36
@@ -40,7 +40,7 @@ Hyperlight also provides tracing capabilities (see below for more details), if n
40
40
41
41
Tracing spans are created for any call to a public API and the parent span will be set to the current span in the host if one exists, the level of the span is set to `info`. The span will be closed when the call returns. Any Result that contains an error variant will be logged as an error event. In addition to the public APIs, all internal functions are instrumented with trace spans at the `trace` level, therefore in order to see full trace information, the trace level should be enabled.
42
42
43
-
Hyperlight provides tracing using the Rust [tracing crate](https://docs.rs/tracing/0.1.37/tracing/), and can be consumed by any Rust trace subscriber implementation(see[here](https://docs.rs/tracing/latest/tracing/index.html#related-crates) for some examples). In addition to consuming trace output the log records may also be consumed by a tracing subscriber, using the `tracing-log`crate.
43
+
Hyperlight provides tracing using the Rust [tracing crate](https://docs.rs/tracing/0.1.37/tracing/), and can be consumed by any Rust trace subscriber implementation(see[here](https://docs.rs/tracing/latest/tracing/index.html#related-crates) for some examples). When no tracing subscriber is set, trace events are automatically forwarded to the `log` facade via the `log` feature of the `tracing` crate, so consumers using only a `log`logger will still receive these events.
44
44
45
45
There are two examples that show how to consume both tracing events and log records as tracing events.
Copy file name to clipboardExpand all lines: src/hyperlight_host/src/sandbox/outb.rs
+87-73Lines changed: 87 additions & 73 deletions
Original file line number
Diff line number
Diff line change
@@ -19,10 +19,9 @@ use std::sync::{Arc, Mutex};
19
19
use hyperlight_common::flatbuffer_wrappers::function_types::{FunctionCallResult,ParameterValue};
20
20
use hyperlight_common::flatbuffer_wrappers::guest_error::{ErrorCode,GuestError};
21
21
use hyperlight_common::flatbuffer_wrappers::guest_log_data::GuestLogData;
22
+
use hyperlight_common::flatbuffer_wrappers::guest_log_level::LogLevel;
22
23
use hyperlight_common::outb::{Exception,OutBAction};
23
-
use log::{Level,Record};
24
24
use tracing::{Span, instrument};
25
-
use tracing_log::format_trace;
26
25
27
26
usesuper::host_funcs::FunctionRegistry;
28
27
#[cfg(feature = "mem_profile")]
@@ -46,8 +45,6 @@ pub enum HandleOutbError {
46
45
InvalidPort(String),
47
46
#[error("Failed to read guest log data: {0}")]
48
47
ReadLogData(String),
49
-
#[error("Trace formatting error: {0}")]
50
-
TraceFormat(String),
51
48
#[error("Failed to read host function call: {0}")]
52
49
ReadHostFunctionCall(String),
53
50
#[error("Failed to acquire lock at {0}:{1} - {2}")]
@@ -65,64 +62,77 @@ pub enum HandleOutbError {
65
62
pub(super)fnoutb_log(
66
63
mgr:&mutSandboxMemoryManager<HostSharedMemory>,
67
64
) -> Result<(),HandleOutbError>{
68
-
// This code will create either a logging record or a tracing record for the GuestLogData depending on if the host has set up a tracing subscriber.
69
-
// In theory as we have enabled the log feature in the Cargo.toml for tracing this should happen
70
-
// automatically (based on if there is tracing subscriber present) but only works if the event created using macros. (see https://github.com/tokio-rs/tracing/blob/master/tracing/src/macros.rs#L2421 )
71
-
// The reason that we don't want to use the tracing macros is that we want to be able to explicitly
72
-
// set the file and line number for the log record which is not possible with macros.
73
-
// This is because the file and line number come from the guest not the call site.
// We cannot get the parent span using the `current_span()` method as by the time we get to this point that span has been exited so there is no current span
428
446
// We need to make sure that the span that we created is in the spans map instead
429
-
// We expect to have created 21 spans at this point. We are only interested in the first one that was created when calling outb_log.
447
+
// We are only interested in the first one that was created when calling outb_log.
430
448
431
-
assert!(
432
-
spans.len() == 21,
433
-
"expected 21 spans, found {}",
434
-
spans.len()
435
-
);
449
+
assert!(!spans.is_empty(),"expected at least one span, found none");
0 commit comments