1const CORRELATION_HEADERS: &[&str] = &[
2 "x-request-id",
3 "x-correlation-id",
4 "traceparent",
5 "x-amzn-trace-id",
6 "cf-ray",
7 "x-datadog-trace-id",
8];
9
10pub fn extract_correlation(headers: &[(String, String)]) -> Vec<(String, String)> {
13 let mut out = Vec::new();
14 for known in CORRELATION_HEADERS {
15 if let Some((_, v)) = headers.iter().find(|(n, _)| n.eq_ignore_ascii_case(known)) {
16 out.push((known.to_string(), v.clone()));
17 }
18 }
19 out
20}
21
22#[cfg(test)]
23mod tests {
24 use super::extract_correlation;
25
26 #[test]
27 fn extracts_known_headers_case_insensitively() {
28 let headers = vec![
29 ("Content-Type".to_string(), "application/json".to_string()),
30 ("X-Request-Id".to_string(), "abc-123".to_string()),
31 ("cf-ray".to_string(), "7d-DFW".to_string()),
32 ];
33 let got = extract_correlation(&headers);
34 assert!(got.contains(&("x-request-id".to_string(), "abc-123".to_string())));
35 assert!(got.contains(&("cf-ray".to_string(), "7d-DFW".to_string())));
36 assert_eq!(got.len(), 2);
37 }
38}