use crate::broker::protocol::Frame;
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct TraceContext {
pub request_id: u64,
pub traceparent: String,
pub tracestate: String,
}
impl TraceContext {
pub fn from_frame(frame: &Frame) -> Self {
Self {
request_id: frame.request_id,
traceparent: frame.traceparent.clone(),
tracestate: frame.tracestate.clone(),
}
}
pub fn backend_headers(&self) -> Vec<(&'static str, String)> {
let mut headers = Vec::new();
if !self.traceparent.is_empty() {
headers.push(("traceparent", self.traceparent.clone()));
}
if !self.tracestate.is_empty() {
headers.push(("tracestate", self.tracestate.clone()));
}
headers
}
}