Crate rustracing

Source
Expand description

OpenTracing API for Rust

§Examples

use rustracing::sampler::AllSampler;
use rustracing::tag::Tag;
use rustracing::Tracer;
use std::thread;
use std::time::Duration;

// Creates a tracer
let (span_tx, span_rx) = crossbeam_channel::bounded(10);
let tracer = Tracer::with_sender(AllSampler, span_tx);
{
    // Starts "parent" span
    let parent_span = tracer.span("parent").start_with_state(());
    thread::sleep(Duration::from_millis(10));
    {
        // Starts "child" span
        let mut child_span = tracer
            .span("child_span")
            .child_of(&parent_span)
            .tag(Tag::new("key", "value"))
            .start_with_state(());

        child_span.log(|log| {
            log.error().message("a log message");
        });
    } // The "child" span dropped and will be sent to `span_rx`
} // The "parent" span dropped and will be sent to `span_rx`

// Outputs finished spans to the standard output
while let Ok(span) = span_rx.try_recv() {
    println!("# SPAN: {:?}", span);
}

As an actual usage example of the crate and an implmentation of the OpenTracing API, it may be helpful to looking at rustracing_jaeger crate.

§References

Modules§

carrier
Traits for representing carriers that propagate span contexts across process boundaries.
convert
Traits for conversions between types.
log
Span log.
sampler
Sampler trait and its built-in implementations.
span
Span.
tag
Span tag.

Structs§

Error
This crate specific error type.
Tracer
Tracer.

Enums§

ErrorKind
The list of the possible error kinds

Type Aliases§

Result
This crate specific Result type.