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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
extern crate failure;
extern crate humthreads;
extern crate iron;
extern crate opentracingrust;
extern crate opentracingrust_zipkin;
extern crate reqwest;
extern crate serde;
extern crate serde_derive;
#[cfg(test)]
extern crate serde_yaml;
extern crate slog;
extern crate replicante_util_failure;
extern crate replicante_util_upkeep;
use std::sync::Arc;
use std::time::Duration;
use opentracingrust::Tracer;
use slog::Logger;
use replicante_util_upkeep::Upkeep;
mod backends;
pub mod carriers;
mod config;
mod error;
pub use self::config::Config;
pub use self::error::fail_span;
pub use self::error::Error;
pub use self::error::ErrorKind;
pub use self::error::Result;
#[derive(Clone)]
pub struct MaybeTracer(Option<Arc<Tracer>>);
impl MaybeTracer {
pub fn new<T>(tracer: T) -> MaybeTracer
where
T: Into<Option<Arc<Tracer>>>,
{
MaybeTracer(tracer.into())
}
pub fn with<B, T>(&self, block: B) -> Option<T>
where
B: FnOnce(&Tracer) -> T,
{
match self.0.as_ref() {
None => None,
Some(tracer) => Some(block(tracer)),
}
}
}
pub struct Opts<'a> {
flush_timeout: Duration,
logger: Logger,
service_name: &'a str,
upkeep: &'a mut Upkeep,
}
impl<'a> Opts<'a> {
pub fn new<S>(service_name: S, logger: Logger, upkeep: &'a mut Upkeep) -> Opts<'a>
where
S: Into<&'a str>,
{
Opts {
flush_timeout: Duration::from_secs(1),
logger,
service_name: service_name.into(),
upkeep,
}
}
pub fn flush_timeout(mut self, timeout: Duration) -> Opts<'a> {
self.flush_timeout = timeout;
self
}
}
pub fn tracer(config: Config, opts: Opts) -> Result<Tracer> {
match config {
Config::Noop => self::backends::noop(opts),
Config::Zipkin(config) => self::backends::zipkin(config, opts),
}
}