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
mod opentelemetry;
mod visitor;
pub use crate::opentelemetry::OpenTelemetry;
pub use crate::visitor::OpenTelemetryVisitor;
pub use ::opentelemetry::api::trace::span_context::{SpanId, TraceId};
use ::opentelemetry::exporter::trace::SpanExporter;
use ::opentelemetry::sdk::Config;
use rand::Rng;
use std::collections::HashMap;
#[doc(no_inline)]
pub use tracing_distributed::{TelemetryLayer, TraceCtxError};
#[cfg(feature = "use_parking_lot")]
use parking_lot::Mutex;
#[cfg(not(feature = "use_parking_lot"))]
use std::sync::Mutex;
pub fn register_dist_tracing_root(
trace_id: TraceId,
remote_parent_span: Option<SpanId>,
) -> Result<(), TraceCtxError> {
tracing_distributed::register_dist_tracing_root(trace_id, remote_parent_span)
}
pub fn current_dist_trace_ctx() -> Result<(TraceId, SpanId), TraceCtxError> {
tracing_distributed::current_dist_trace_ctx()
}
pub fn new_blackhole_telemetry_layer(
) -> TelemetryLayer<tracing_distributed::BlackholeTelemetry<SpanId, TraceId>, SpanId, TraceId> {
TelemetryLayer::new(
"opentelemetry_blackhole_tracing_layer",
tracing_distributed::BlackholeTelemetry::default(),
|tracing_id| SpanId::from_u64(tracing_id.into_u64()),
)
}
pub fn new_opentelemetry_layer(
service_name: &'static str,
exporter: Box<dyn SpanExporter>,
config: Config,
) -> TelemetryLayer<OpenTelemetry, SpanId, TraceId> {
let r: u64 = rand::thread_rng().gen();
TelemetryLayer::new(
service_name,
OpenTelemetry {
exporter,
events: Mutex::new(HashMap::new()),
config,
},
move |tracing_id| SpanId::from_u64(tracing_id.into_u64() ^ r),
)
}