3 stable releases

new 1.1.0 Dec 9, 2024
1.0.1 Aug 22, 2024
1.0.0 Apr 30, 2024

#284 in Web programming

Download history 274/week @ 2024-08-18 1759/week @ 2024-08-25 2409/week @ 2024-09-01 2784/week @ 2024-09-08 2695/week @ 2024-09-15 2949/week @ 2024-09-22 2644/week @ 2024-09-29 3179/week @ 2024-10-06 3375/week @ 2024-10-13 3539/week @ 2024-10-20 3993/week @ 2024-10-27 4449/week @ 2024-11-03 6644/week @ 2024-11-10 8756/week @ 2024-11-17 8125/week @ 2024-11-24 7975/week @ 2024-12-01

31,843 downloads per month
Used in 3 crates

MIT license

54KB
1K SLoC

cf-rustracing

Crates.io: cf-rustracing Documentation License: MIT

OpenTracing API for Rust.

Documentation

Examples

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

#[tokio::main]
async fn main() {
    // Creates a tracer
    let (tracer, mut span_rx) = Tracer::new(AllSampler);
    {
        // 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`
    
    println!("# SPAN: {:?}", span_rx.recv().await);
    println!("# SPAN: {:?}", span_rx.recv().await);
}

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

~3.5–9.5MB
~91K SLoC