Trait heph::trace::Trace[][src]

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::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

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.

Finish tracing an event, partner function to start_trace.

See the trace module for more information, e.g. what each argument means.

Implementors