Files
codex/codex-rs/exec-server/src/trace_context.rs
Ben Romano 45cf6cbc19 Propagate caller metadata to rendezvous connections (#39073)
## What changed

- Add `x-cluster-name` from `OPENAI_CLUSTER` and
  `x-openai-internal-caller` from `DD_SERVICE` to rendezvous WebSocket
  handshakes when the environment values are nonempty and valid HTTP header
  values.
- Apply the rendezvous headers to both client and remote executor connections
  while preserving the existing W3C trace context headers.

GitOrigin-RevId: fead0244ba24fa208990b92d2170a9ae76ff2ceb
2026-08-17 20:36:10 +00:00

41 lines
1.1 KiB
Rust

use http::HeaderMap;
use http::HeaderValue;
pub(crate) fn current_rendezvous_headers() -> HeaderMap {
let mut headers = current_trace_context_headers();
for (header, variable) in [
("x-cluster-name", "OPENAI_CLUSTER"),
("x-openai-internal-caller", "DD_SERVICE"),
] {
if let Ok(value) = std::env::var(variable)
&& !value.is_empty()
&& let Ok(value) = HeaderValue::try_from(value)
{
headers.insert(header, value);
}
}
headers
}
pub(crate) fn current_trace_context_headers() -> HeaderMap {
let mut headers = HeaderMap::new();
let Some(trace) = codex_otel::current_span_w3c_trace_context() else {
return headers;
};
if let Some(traceparent) = trace.traceparent
&& let Ok(value) = HeaderValue::try_from(traceparent)
{
headers.insert("traceparent", value);
}
if let Some(tracestate) = trace.tracestate
&& let Ok(value) = HeaderValue::try_from(tracestate)
{
headers.insert("tracestate", value);
}
headers
}
#[cfg(test)]
#[path = "trace_context_tests.rs"]
mod tests;