Extract a `TraceId` from HTTP request headers. Priority order: 1. W3C `traceparent` (full 16-byte trace ID extracted from the 32-hex field). 2. `X-Trace-ID` (32 hex chars interpreted as 16 bytes). 3. Generate a fresh ID.
(headers: &axum::http::HeaderMap)
| 26 | /// 2. `X-Trace-ID` (32 hex chars interpreted as 16 bytes). |
| 27 | /// 3. Generate a fresh ID. |
| 28 | pub fn extract_from_headers(headers: &axum::http::HeaderMap) -> TraceId { |
| 29 | // 1. W3C traceparent: "00-<32hex>-<16hex>-<2hex>" |
| 30 | if let Some(val) = headers.get("traceparent") |
| 31 | && let Ok(s) = val.to_str() |
| 32 | && let Some((tid, _sid, _flags)) = TraceId::from_traceparent(s) |
| 33 | { |
| 34 | return tid; |
| 35 | } |
| 36 | |
| 37 | // 2. X-Trace-ID: 32 lowercase hex chars. |
| 38 | if let Some(val) = headers.get("x-trace-id") |
| 39 | && let Ok(s) = val.to_str() |
| 40 | && let Ok(tid) = s.parse::<TraceId>() |
| 41 | { |
| 42 | return tid; |
| 43 | } |
| 44 | |
| 45 | // 3. No trace ID supplied — generate one. |
| 46 | TraceId::generate() |
| 47 | } |
| 48 | |
| 49 | /// Extract a `TraceId` from a pgwire startup parameter map. |
| 50 | /// |