• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

sile / rustracing / 9526165797

15 Jun 2024 06:30AM UTC coverage: 74.576%. Remained the same
9526165797

push

github

web-flow
Merge pull request #16 from sile/fix-lint-error

Fix clippy errors

1 of 1 new or added line in 1 file covered. (100.0%)

264 of 354 relevant lines covered (74.58%)

2.61 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/tracer.rs
1
use crate::sampler::Sampler;
2
use crate::span::{SpanReceiver, SpanSender, StartSpanOptions};
3
use std::borrow::Cow;
4
use std::sync::Arc;
5

6
/// Tracer.
7
///
8
/// # Examples
9
///
10
/// ```
11
/// use rustracing::Tracer;
12
/// use rustracing::sampler::AllSampler;
13
///
14
/// let (span_tx, span_rx) = crossbeam_channel::bounded(10);
15
/// let tracer = Tracer::with_sender(AllSampler, span_tx);
16
/// {
17
///    let _span = tracer.span("foo").start_with_state(());
18
/// }
19
/// let span = span_rx.try_recv().unwrap();
20
/// assert_eq!(span.operation_name(), "foo");
21
/// ```
22
#[derive(Debug)]
23
pub struct Tracer<S, T> {
24
    sampler: Arc<S>,
25
    span_tx: SpanSender<T>,
26
}
27
impl<S: Sampler<T>, T> Tracer<S, T> {
28
    /// This constructor is mainly for backward compatibility, it has the same interface
29
    /// as in previous versions except the type of `SpanReceiver`.
30
    /// It builds an unbounded channel which may cause memory issues if there is no reader,
31
    /// prefer `with_sender()` alternative with a bounded one.
32
    pub fn new(sampler: S) -> (Self, SpanReceiver<T>) {
33
        let (span_tx, span_rx) = crossbeam_channel::unbounded();
34
        (Self::with_sender(sampler, span_tx), span_rx)
35
    }
36

37
    /// Makes a new `Tracer` instance.
38
    pub fn with_sender(sampler: S, span_tx: SpanSender<T>) -> Self {
3✔
39
        Tracer {
3✔
40
            sampler: Arc::new(sampler),
3✔
41
            span_tx,
42
        }
43
    }
3✔
44

45
    /// Returns `StartSpanOptions` for starting a span which has the name `operation_name`.
46
    pub fn span<N>(&self, operation_name: N) -> StartSpanOptions<S, T>
5✔
47
    where
48
        N: Into<Cow<'static, str>>,
49
    {
50
        StartSpanOptions::new(operation_name, &self.span_tx, &self.sampler)
5✔
51
    }
5✔
52
}
53
impl<S, T> Tracer<S, T> {
54
    /// Clone with the given `sampler`.
55
    pub fn clone_with_sampler<U: Sampler<T>>(&self, sampler: U) -> Tracer<U, T> {
56
        Tracer {
57
            sampler: Arc::new(sampler),
58
            span_tx: self.span_tx.clone(),
59
        }
60
    }
61
}
62
impl<S, T> Clone for Tracer<S, T> {
63
    fn clone(&self) -> Self {
64
        Tracer {
65
            sampler: Arc::clone(&self.sampler),
66
            span_tx: self.span_tx.clone(),
67
        }
68
    }
69
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc