Specialize blocking OTLP/HTTP providers for single-signal export (#63406)

## Why

The code-mode host only exports traces, and Windows sandbox setup only
exports metrics. Selecting the required exporter and HTTP client at compile
time lets the linker drop unused exporter and custom client code.

## What changed

Use `BlockingHttpService` for OTLP/HTTP JSON traces in the code-mode host
and Statsig metrics during Windows sandbox setup. These providers use the
OpenTelemetry SDK's default HTTP client. Traces use the dedicated batch span
processor even inside a Tokio runtime.

Move `codex_home` from `OtelSettings` to `OtelHeadersHelper`, where it
supplies the working directory for user-configured header commands.

## Testing

Exercise the blocking providers in HTTP loopback tests for trace export
inside a current-thread Tokio runtime and cumulative metrics temporality.

GitOrigin-RevId: 21bacbdb18b603f5f536532812ce7643e4eb36d6
This commit is contained in:
Charlie Marsh
2026-11-23 18:44:09 +00:00
committed by copyberry
parent 78fe0c9f23
commit 69477b3a77
20 changed files with 245 additions and 232 deletions
+1 -1
View File
@@ -17,7 +17,6 @@ path = "src/lib.rs"
workspace = true
[dependencies]
codex-http-client = { workspace = true }
anyhow = { workspace = true }
axum = { workspace = true, features = ["http1", "tokio", "ws"] }
clap = { workspace = true, features = ["derive"] }
@@ -39,6 +38,7 @@ uuid = { workspace = true, features = ["v4"] }
[dev-dependencies]
codex-core = { workspace = true }
codex-http-client = { workspace = true }
tokio = { workspace = true, features = ["test-util"] }
codex-plugin-host = { workspace = true }
codex-code-mode = { workspace = true }
+8 -30
View File
@@ -1,14 +1,8 @@
use std::collections::BTreeMap;
use std::collections::HashMap;
use std::path::PathBuf;
use std::time::Duration;
use anyhow::Context;
use clap::Parser;
use codex_otel::OtelExporter;
use codex_otel::OtelHttpProtocol;
use codex_otel::BlockingHttpService;
use codex_otel::OtelProvider;
use codex_otel::OtelSettings;
use codex_otel_trace_websocket::TraceWebSocket;
use tracing_subscriber::Layer;
use tracing_subscriber::layer::SubscriberExt;
@@ -103,27 +97,11 @@ fn main() -> anyhow::Result<()> {
}
fn build_trace_provider(endpoint: &str) -> anyhow::Result<OtelProvider> {
OtelProvider::try_new_http_traces(&OtelSettings {
headers_helper: None,
http_client_factory: codex_http_client::HttpClientFactory::new(
codex_http_client::OutboundProxyPolicy::ReqwestDefault,
),
environment: "code-mode-host".to_string(),
service_name: "codex-code-mode-host".to_string(),
service_version: env!("CARGO_PKG_VERSION").to_string(),
codex_home: PathBuf::from("/tmp"),
exporter: OtelExporter::None,
trace_exporter: OtelExporter::OtlpHttp {
endpoint: endpoint.to_string(),
headers: HashMap::new(),
protocol: OtelHttpProtocol::Json,
tls: None,
},
metrics_exporter: OtelExporter::None,
runtime_metrics: false,
span_attributes: HashMap::new(),
tracestate: BTreeMap::new(),
})
.map_err(|error| anyhow::anyhow!("failed to build code-mode host OTEL provider: {error}"))?
.context("code-mode host OTEL trace provider was unexpectedly disabled")
BlockingHttpService {
environment: "code-mode-host",
name: "codex-code-mode-host",
version: env!("CARGO_PKG_VERSION"),
}
.traces(endpoint)
.map_err(|error| anyhow::anyhow!("failed to build code-mode host OTEL provider: {error}"))
}