2 stable releases

1.0.1 Aug 22, 2024
1.0.0 Apr 30, 2024

#304 in Web programming

Download history 9/week @ 2024-07-03 188/week @ 2024-07-10 109/week @ 2024-07-17 78/week @ 2024-07-24 100/week @ 2024-07-31 93/week @ 2024-08-07 91/week @ 2024-08-14 577/week @ 2024-08-21 2504/week @ 2024-08-28 2689/week @ 2024-09-04 2813/week @ 2024-09-11 2760/week @ 2024-09-18 2751/week @ 2024-09-25 2731/week @ 2024-10-02 3235/week @ 2024-10-09 3752/week @ 2024-10-16

13,054 downloads per month
Used in 2 crates

MIT license

52KB
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–9MB
~90K SLoC