19 releases

0.6.0 Apr 5, 2022
0.5.1 Jan 13, 2021
0.5.0 Oct 25, 2020
0.4.0 Feb 3, 2020
0.1.4 Oct 19, 2017

#1 in #tracer

Download history 3069/week @ 2023-11-24 3049/week @ 2023-12-01 3233/week @ 2023-12-08 4416/week @ 2023-12-15 1733/week @ 2023-12-22 2389/week @ 2023-12-29 4870/week @ 2024-01-05 5303/week @ 2024-01-12 5641/week @ 2024-01-19 6652/week @ 2024-01-26 5949/week @ 2024-02-02 6879/week @ 2024-02-09 6500/week @ 2024-02-16 6718/week @ 2024-02-23 9354/week @ 2024-03-01 4434/week @ 2024-03-08

28,317 downloads per month
Used in 26 crates (10 directly)

MIT license

54KB
1K SLoC

rustracing

Crates.io: rustracing Documentation Actions Status Coverage Status License: MIT

OpenTracing API for Rust.

Documentation

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 implementation of the OpenTracing API, it may be helpful to looking at rustracing_jaeger crate.

References

Dependencies

~1.7–2.6MB
~55K SLoC