pub trait Trace {
fn start_trace(&self) -> Option<EventTiming>;
fn finish_trace(
&mut self,
timing: Option<EventTiming>,
description: &str,
attributes: &[(&str, &dyn AttributeValue)]
);
}Expand description
Trace events.
See the trace module for usage.
Examples
The following example adds tracing for receiving and handling of a message.
use heph::actor;
use heph_rt::ThreadLocal;
use heph_rt::trace::Trace;
async fn actor(mut ctx: actor::Context<String, ThreadLocal>) {
// Start a trace of receiving and handling a message.
let mut trace_timing = ctx.start_trace();
while let Ok(msg) = ctx.receive_next().await {
// Finish the trace for receiving the message.
ctx.finish_trace(trace_timing.clone(), "receiving message", &[("message", &msg)]);
// Handle the message by printing it.
let print_timing = ctx.start_trace();
println!("got a message: {}", msg);
// Finish the trace for the printing and handling of the message.
ctx.finish_trace(print_timing, "Printing message", &[]);
ctx.finish_trace(trace_timing, "Handling message", &[]);
// Start tracing the next message.
trace_timing = ctx.start_trace();
}
}
Required Methods
fn start_trace(&self) -> Option<EventTiming>
fn start_trace(&self) -> Option<EventTiming>
Start timing an event if tracing is enabled.
To finish the trace call finish_trace. See the trace module for
more information.
Notes
If finish_trace is not called no trace event will be written. Be
careful with this when using the Try (?) operator.
fn finish_trace(
&mut self,
timing: Option<EventTiming>,
description: &str,
attributes: &[(&str, &dyn AttributeValue)]
)
fn finish_trace(
&mut self,
timing: Option<EventTiming>,
description: &str,
attributes: &[(&str, &dyn AttributeValue)]
)
Finish tracing an event, partner function to start_trace.
See the trace module for more information, e.g. what each argument
means.