use std::collections::BTreeMap; #[derive(Clone, Debug, PartialEq, Eq)] pub struct RuntimeRequestContext { pub request_id: String, pub correlation_id: String, } impl RuntimeRequestContext { pub fn new(request_id: impl Into, correlation_id: impl Into) -> Self { Self { request_id: request_id.into(), correlation_id: correlation_id.into(), } } pub fn from_request_id(request_id: impl Into) -> Self { let request_id = request_id.into(); Self::new(request_id.clone(), request_id) } pub fn outbound_headers(&self) -> BTreeMap { BTreeMap::from([ ("x-request-id".to_owned(), self.request_id.clone()), ("x-correlation-id".to_owned(), self.correlation_id.clone()), ]) } } #[cfg(test)] mod tests { use super::RuntimeRequestContext; #[test] fn uses_request_id_for_default_correlation_id() { let context = RuntimeRequestContext::from_request_id("req_123"); assert_eq!(context.request_id, "req_123"); assert_eq!(context.correlation_id, "req_123"); } }