Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(progress_tracing): route otlp span pushes through the runtime proxy

Steven Enamakelf591c9cbdaee
diff --git a/crates/openhuman-core/src/agent/progress_tracing/otlp.rs b/crates/openhuman-core/src/agent/progress_tracing/otlp.rs
index 836523c008..62a6238a46 100644
--- a/crates/openhuman-core/src/agent/progress_tracing/otlp.rs
+++ b/crates/openhuman-core/src/agent/progress_tracing/otlp.rs
@@ -13,6 +13,16 @@ use crate::config::Config;
use crate::security::credentials::jwt::bearer_authorization_value;
use crate::security::credentials::session_support::direct_backend_credential;
+/// Service key the push is proxied under (`ProxyConfig::services`).
+pub(super) const OTLP_SERVICE_KEY: &str = "telemetry.otlp";
+
+/// The push's HTTP client: the runtime proxy and platform TLS roots apply, and
+/// the underlying client is cached per service key, so every push reuses one
+/// connection pool.
+pub(super) fn otlp_client() -> reqwest::Client {
+ crate::config::build_runtime_proxy_client_with_timeouts(OTLP_SERVICE_KEY, 10, 10)
+}
+
pub(super) async fn push_spans(config: &Config, spans: &[TraceSpan]) -> Result<(), String> {
if spans.is_empty() {
return Ok(());
@@ -37,13 +47,11 @@ pub(super) async fn push_spans(config: &Config, spans: &[TraceSpan]) -> Result<(
// Backend traffic: stamp the host's attribution headers (product
// identity, versions) resolved onto the config.
let attribution = config.resolved_endpoints.attribution_header_map();
- let client = reqwest::Client::builder()
- .default_headers(attribution)
- .build()
- .map_err(|err| format!("Langfuse OTLP client build failed: {err}"))?;
+ let client = otlp_client();
for payload in otlp_requests(spans, environment, &super::export_brand()) {
let response = client
.post(&url)
+ .headers(attribution.clone())
.header(
reqwest::header::AUTHORIZATION,
bearer_authorization_value(&token),
diff --git a/crates/openhuman-core/src/agent/progress_tracing/otlp_tests.rs b/crates/openhuman-core/src/agent/progress_tracing/otlp_tests.rs
index 8429643aca..556739dac1 100644
--- a/crates/openhuman-core/src/agent/progress_tracing/otlp_tests.rs
+++ b/crates/openhuman-core/src/agent/progress_tracing/otlp_tests.rs
@@ -21,3 +21,45 @@ async fn external_backend_is_skipped_before_session_lookup() {
}];
assert!(push_spans(&config, &spans).await.is_ok());
}
+
+/// The push must honour the host's runtime proxy (and so its CA/TLS setup)
+/// rather than build a bare client.
+#[tokio::test]
+async fn the_push_client_goes_through_the_runtime_proxy() {
+ use crate::config::schema::{ProxyConfig, ProxyScope};
+ use crate::config::{runtime_proxy_config, set_runtime_proxy_config};
+ use std::io::Read;
+
+ let _env = crate::config::TEST_ENV_LOCK.lock().await;
+ let listener = std::net::TcpListener::bind("127.0.0.1:0").unwrap();
+ let port = listener.local_addr().unwrap().port();
+ let (tx, rx) = std::sync::mpsc::channel::<String>();
+ std::thread::spawn(move || {
+ if let Ok((mut stream, _)) = listener.accept() {
+ let mut buf = [0u8; 1024];
+ let n = stream.read(&mut buf).unwrap_or(0);
+ let _ = tx.send(String::from_utf8_lossy(&buf[..n]).into_owned());
+ }
+ });
+ let previous = runtime_proxy_config();
+ set_runtime_proxy_config(ProxyConfig {
+ enabled: true,
+ http_proxy: Some(format!("http://127.0.0.1:{port}")),
+ scope: ProxyScope::Services,
+ services: vec![OTLP_SERVICE_KEY.into()],
+ ..ProxyConfig::default()
+ });
+ let _ = otlp_client()
+ .post("http://otlp.proxy-test.invalid/v1/traces")
+ .body("{}")
+ .send()
+ .await;
+ set_runtime_proxy_config(previous);
+ let seen = rx
+ .recv_timeout(std::time::Duration::from_secs(5))
+ .expect("the proxy saw the request");
+ assert!(
+ seen.starts_with("POST http://otlp.proxy-test.invalid/v1/traces"),
+ "{seen}"
+ );
+}
diff --git a/crates/openhuman-core/src/config/schema/proxy.rs b/crates/openhuman-core/src/config/schema/proxy.rs
index f1fe558f84..7a9a6e76ee 100644
--- a/crates/openhuman-core/src/config/schema/proxy.rs
+++ b/crates/openhuman-core/src/config/schema/proxy.rs
@@ -34,6 +34,7 @@ const SUPPORTED_PROXY_SERVICE_KEYS: &[&str] = &[
"tool.pushover",
"memory.embeddings",
"tunnel.custom",
+ "telemetry.otlp",
];
const SUPPORTED_PROXY_SERVICE_SELECTORS: &[&str] =