running_process/broker/server/
trace_context.rs1use crate::broker::protocol::Frame;
4
5#[derive(Clone, Debug, Default, PartialEq, Eq)]
7pub struct TraceContext {
8 pub request_id: u64,
10 pub traceparent: String,
12 pub tracestate: String,
14}
15
16impl TraceContext {
17 pub fn from_frame(frame: &Frame) -> Self {
19 Self {
20 request_id: frame.request_id,
21 traceparent: frame.traceparent.clone(),
22 tracestate: frame.tracestate.clone(),
23 }
24 }
25
26 pub fn backend_headers(&self) -> Vec<(&'static str, String)> {
28 let mut headers = Vec::new();
29 if !self.traceparent.is_empty() {
30 headers.push(("traceparent", self.traceparent.clone()));
31 }
32 if !self.tracestate.is_empty() {
33 headers.push(("tracestate", self.tracestate.clone()));
34 }
35 headers
36 }
37}