Skip to content

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

refactor(progress_tracing): delegate otlp push to langfuse client

Steven Enamakel3bac9bb63f6f
diff --git a/crates/openhuman-core/src/agent/progress_tracing/otlp.rs b/crates/openhuman-core/src/agent/progress_tracing/otlp.rs
index a850ec2dae..65cc4c4f63 100644
--- a/crates/openhuman-core/src/agent/progress_tracing/otlp.rs
+++ b/crates/openhuman-core/src/agent/progress_tracing/otlp.rs
@@ -4,21 +4,24 @@
//! (`tinyagents_harness::observability::trace_export::otlp`); this module only
//! resolves the backend URL and credential and posts the requests.
-use serde_json::Value;
+use std::time::Duration;
+
use tinyagents_harness::observability::trace_export::otlp::otlp_requests;
use tinyagents_harness::observability::trace_export::TraceSpan;
+use tinyagents_harness::observability::LangfuseClient;
use super::langfuse::{environment_for_base, ingestion_url, skip_push};
use crate::config::Config;
use crate::security::credentials::jwt::bearer_authorization_value;
use crate::security::credentials::session_support::direct_backend_credential;
+const PUSH_TIMEOUT: Duration = Duration::from_secs(10);
+
pub(super) async fn push_spans(config: &Config, spans: &[TraceSpan]) -> Result<(), String> {
if spans.is_empty() {
return Ok(());
}
- let legacy_url = ingestion_url(config);
- let url = legacy_url.replace("/langfuse/ingestion", "/langfuse/otel/v1/traces");
+ let url = ingestion_url(config);
let environment = environment_for_base(&url);
if skip_push(environment) {
return Ok(());
@@ -35,38 +38,24 @@ pub(super) async fn push_spans(config: &Config, spans: &[TraceSpan]) -> Result<(
}
_ => return Ok(()),
};
- // Backend traffic: the transport's client carries the host's attribution
- // headers (product identity, versions).
- let client = crate::backend::resolve_backend_transport()
+ // Reuse the host's configured API transport for TLS, attribution headers,
+ // and route policy. LangfuseClient owns the proxy route, bearer header,
+ // OTLP v4 header, and response validation.
+ let transport = crate::backend::resolve_backend_transport()
.map_err(|err| format!("Langfuse OTLP push has no backend transport: {err}"))?
- .http_client(crate::backend::TransportProfile::Api);
+ ;
+ let client = LangfuseClient::proxy_with_transport(
+ url,
+ bearer_authorization_value(&token),
+ transport.http_client(crate::backend::TransportProfile::Api),
+ transport.attribution_headers(),
+ )
+ .map_err(|_| "Langfuse OTLP proxy client could not be configured".to_string())?;
for payload in otlp_requests(spans, environment, &super::export_brand()) {
- let response = client
- .post(&url)
- .header(
- reqwest::header::AUTHORIZATION,
- bearer_authorization_value(&token),
- )
- .timeout(std::time::Duration::from_secs(10))
- .json(&payload)
- .send()
+ tokio::time::timeout(PUSH_TIMEOUT, client.send_otlp(payload))
.await
- .map_err(|err| format!("Langfuse OTLP transport failed: {err}"))?;
- let status = response.status();
- if !status.is_success() {
- return Err(format!("Langfuse OTLP proxy returned {status}"));
- }
- let body: Value = response.json().await.unwrap_or(Value::Null);
- if body["partialSuccess"]["rejectedSpans"]
- .as_u64()
- .unwrap_or(0)
- > 0
- || body["partialSuccess"]["errorMessage"]
- .as_str()
- .is_some_and(|message| !message.is_empty())
- {
- return Err("Langfuse OTLP proxy partially rejected spans".to_string());
- }
+ .map_err(|_| "Langfuse OTLP proxy request timed out".to_string())?
+ .map_err(|_| "Langfuse OTLP proxy request failed".to_string())?;
}
Ok(())
}