1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use crate::sampler::Sampler;
use crate::span::{SpanReceiver, SpanSender, StartSpanOptions};
use std::borrow::Cow;
use std::sync::Arc;
#[derive(Debug)]
pub struct Tracer<S, T> {
sampler: Arc<S>,
span_tx: SpanSender<T>,
}
impl<S: Sampler<T>, T> Tracer<S, T> {
pub fn new(sampler: S) -> (Self, SpanReceiver<T>) {
let (span_tx, span_rx) = crossbeam_channel::unbounded();
(Self::with_sender(sampler, span_tx), span_rx)
}
pub fn with_sender(sampler: S, span_tx: SpanSender<T>) -> Self {
Tracer {
sampler: Arc::new(sampler),
span_tx,
}
}
pub fn span<N>(&self, operation_name: N) -> StartSpanOptions<S, T>
where
N: Into<Cow<'static, str>>,
{
StartSpanOptions::new(operation_name, &self.span_tx, &self.sampler)
}
}
impl<S, T> Tracer<S, T> {
pub fn clone_with_sampler<U: Sampler<T>>(&self, sampler: U) -> Tracer<U, T> {
Tracer {
sampler: Arc::new(sampler),
span_tx: self.span_tx.clone(),
}
}
}
impl<S, T> Clone for Tracer<S, T> {
fn clone(&self) -> Self {
Tracer {
sampler: Arc::clone(&self.sampler),
span_tx: self.span_tx.clone(),
}
}
}