codex-otel: add configurable trace metadata (#21556)

Add Codex config for static trace span attributes and structured W3C
tracestate field upserts. The config flows through OtelSettings so
callers can attach trace metadata without touching every span call site.

Apply span attributes with an SDK span processor so every exported
trace span carries the configured metadata. Model tracestate as nested
member fields so configured keys can be upserted while unrelated
propagated state in the same member is preserved.

Validate configured tracestate before installing provider-global state,
including header-unsafe values the SDK does not reject by itself. This
keeps Codex from propagating malformed trace context from config.

Update the config schema, public docs, and OTLP loopback coverage for
config parsing, span export, propagation, and invalid-header rejection.
This commit is contained in:
bbrown-oai authored and GitHub committed 2026-05-07 16:06:57 -07:00
1 parent 0d0835dd53
commit 31b233c7c6
16 files changed
+707 -47

No files matched your search

+1
View File
@@ -60,6 +60,7 @@ const PROJECT_LOCAL_CONFIG_DENYLIST: &[&str] = &[
"profile",
"profiles",
"experimental_realtime_ws_base_url",
"otel",
];
async fn first_layer_config_error_from_entries(layers: &[ConfigLayerEntry]) -> Option<ConfigError> {
+10
View File
@@ -514,6 +514,12 @@ pub struct OtelConfigToml {
/// Optional metrics exporter
pub metrics_exporter: Option<OtelExporterKind>,
/// Attributes to add to every exported trace span.
pub span_attributes: Option<BTreeMap<String, String>>,
/// Semicolon-separated `key:value` fields to upsert into W3C tracestate members.
pub tracestate: Option<BTreeMap<String, BTreeMap<String, String>>>,
}
/// Effective OTEL settings after defaults are applied.
@@ -524,6 +530,8 @@ pub struct OtelConfig {
pub exporter: OtelExporterKind,
pub trace_exporter: OtelExporterKind,
pub metrics_exporter: OtelExporterKind,
pub span_attributes: BTreeMap<String, String>,
pub tracestate: BTreeMap<String, BTreeMap<String, String>>,
}
impl Default for OtelConfig {
@@ -534,6 +542,8 @@ impl Default for OtelConfig {
exporter: OtelExporterKind::None,
trace_exporter: OtelExporterKind::None,
metrics_exporter: OtelExporterKind::Statsig,
span_attributes: BTreeMap::new(),
tracestate: BTreeMap::new(),
}
}
}