rivetkit_client_protocol/telemetry_headers.rs
1//! Headers that carry a caller's ray ID and W3C trace context into an actor,
2//! shared by every Rust peer of the actor HTTP surface: the runtime that reads
3//! them and the clients that send them.
4
5/// Bounded correlation string that follows work across actors, surviving
6/// sampling and trace-root boundaries.
7pub const HEADER_RIVET_RAY_ID: &str = "x-rivet-ray-id";
8pub const HEADER_TRACEPARENT: &str = "traceparent";
9pub const HEADER_TRACESTATE: &str = "tracestate";
10
11/// W3C Baggage key that carries a ray ID through application code, so a request
12/// handler that received a ray ID can hand it to the actors it calls.
13pub const RAY_BAGGAGE_KEY: &str = "rivet.ray.id";
14
15const RAY_ID_MAX_LEN: usize = 30;
16
17/// Returns `value` when it is a ray ID the runtime accepts: 1 to 30 characters
18/// of `[A-Za-z0-9_-]`. The value arrives from a caller, so anything else
19/// counts as absent.
20pub fn bounded_ray_id(value: &str) -> Option<&str> {
21 let valid = !value.is_empty()
22 && value.len() <= RAY_ID_MAX_LEN
23 && value
24 .bytes()
25 .all(|byte| byte.is_ascii_alphanumeric() || matches!(byte, b'-' | b'_'));
26 if valid { Some(value) } else { None }
27}