aboutsummaryrefslogtreecommitdiff
path: root/src/client.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2022-02-18 19:01:23 +0100
committerAlex Auvolat <alex@adnab.me>2022-02-18 19:01:59 +0100
commitab0f7785ae73e2f5aaf912fc3c0f2cd724967546 (patch)
treeaa5b6d95dd7ccb4560e02352a8c980d077edfed1 /src/client.rs
parentdc0b5c0305284a1f33417e184c1e4d0ef6e7c032 (diff)
downloadnetapp-ab0f7785ae73e2f5aaf912fc3c0f2cd724967546.tar.gz
netapp-ab0f7785ae73e2f5aaf912fc3c0f2cd724967546.zip
Add telemetry
Diffstat (limited to 'src/client.rs')
-rw-r--r--src/client.rs31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/client.rs b/src/client.rs
index ca1bcf9..7ef772d 100644
--- a/src/client.rs
+++ b/src/client.rs
@@ -125,10 +125,39 @@ impl ClientConn {
.next_query_number
.fetch_add(1, atomic::Ordering::Relaxed);
- let mut bytes = vec![prio, path.as_bytes().len() as u8];
+ cfg_if::cfg_if! {
+ if #[cfg(feature = "telemetry")] {
+ use opentelemetry::{trace::{TraceId, TraceContextExt}, Context};
+ let trace_id_int = Context::current()
+ .span()
+ .span_context()
+ .trace_id();
+ let trace_id = if trace_id_int == TraceId::INVALID {
+ None
+ } else {
+ Some(trace_id_int.to_bytes().to_vec())
+ };
+ } else {
+ let trace_id: Option<Vec<u8>> = None;
+ }
+ };
+
+ // Encode request
+ let mut bytes = vec![];
+
+ bytes.extend_from_slice(&[prio, path.as_bytes().len() as u8]);
bytes.extend_from_slice(path.as_bytes());
+
+ if let Some(by) = trace_id {
+ bytes.push(by.len() as u8);
+ bytes.extend(by);
+ } else {
+ bytes.push(0);
+ }
+
bytes.extend_from_slice(&rmp_to_vec_all_named(rq)?[..]);
+ // Send request through
let (resp_send, resp_recv) = oneshot::channel();
let old = self.inflight.lock().unwrap().insert(id, resp_send);
if let Some(old_ch) = old {