Skip to content

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

feat(progress_tracing): add langfuse trace field handling

Steven Enamakel57fcc59226cb
diff --git a/crates/openhuman-core/src/agent/progress_tracing/langfuse.rs b/crates/openhuman-core/src/agent/progress_tracing/langfuse.rs
index 6b9f10d2d4..0a5373541e 100644
--- a/crates/openhuman-core/src/agent/progress_tracing/langfuse.rs
+++ b/crates/openhuman-core/src/agent/progress_tracing/langfuse.rs
@@ -2,16 +2,12 @@
//! (issue #4249 follow-up).
//!
//! When `observability.share_usage_data` is enabled, a completed run's spans
-//! are POSTed as OTLP/HTTP JSON (see [`super::otlp`]) to the OpenHuman
-//! backend's Langfuse **proxy**, `/telemetry/langfuse/otel/v1/traces`, which
-//! sits beside the legacy `/telemetry/langfuse/ingestion` route
-//! [`ingestion_url`] resolves from the **current backend hostname**
-//! (`effective_backend_api_url`). The request reuses the OpenHuman **session
-//! bearer**; the backend authenticates that JWT, stamps the user on every span,
-//! injects the Langfuse project keys server-side, and forwards to Langfuse
-//! v4's `/api/public/otel/v1/traces` (backend `src/services/langfuseProxy.ts`).
-//! Clients never hold Langfuse keys. The legacy batch route is no longer used
-//! for traces: Langfuse Cloud removes it on 2026-11-16.
+//! are POSTed as OTLP/HTTP JSON (see [`super::otlp`]) to the tracing proxy of
+//! the host's backend, at the URL the host resolved onto the config
+//! (`resolved_endpoints.tracing_otlp_url`, see [`otlp_url`]) so it always
+//! follows the current backend hostname. The request reuses the session
+//! bearer; the backend authenticates that JWT, stamps the user on every span
+//! and holds the tracing project keys itself, so clients never hold them.
//!
//! Best-effort: any failure is logged and swallowed by the caller so tracing
//! never breaks a turn. Spans always carry metadata (names, kinds, timings,
diff --git a/crates/openhuman-core/src/agent/progress_tracing/langfuse_batch_tests.rs b/crates/openhuman-core/src/agent/progress_tracing/langfuse_batch_tests.rs
index 11a056c57f..3dc6b75c66 100644
--- a/crates/openhuman-core/src/agent/progress_tracing/langfuse_batch_tests.rs
+++ b/crates/openhuman-core/src/agent/progress_tracing/langfuse_batch_tests.rs
@@ -23,73 +23,88 @@ fn an_unrecognised_environment_fails_closed() {
}
}
+/// A config as the installed host's enricher resolves it for a hosted
+/// control plane in `environment`.
+fn config_resolved_as(environment: &str) -> Config {
+ let mut config = Config::default();
+ config.resolved_endpoints.deployment_environment = Some(environment.to_string());
+ config
+}
+
#[test]
fn every_environment_for_base_bucket_is_classified_deliberately() {
// Ties the two functions together: if `environment_for_base` grows a
// bucket, this fails until someone decides which side it belongs on.
+ for (resolved, base) in [
+ ("staging", "https://staging.example.test"),
+ ("production", "https://api.example.test"),
+ ] {
+ let config = config_resolved_as(resolved);
+ assert!(push_allowed(environment_for_base(&config, base)));
+ }
assert!(push_allowed(environment_for_base(
- "https://staging-api.tinyhumans.ai"
- )));
- assert!(push_allowed(environment_for_base("http://localhost:7788")));
- assert!(push_allowed(environment_for_base(
- "https://api.tinyhumans.ai"
+ &Config::default(),
+ "http://localhost:7788"
)));
}
#[test]
-fn ingestion_url_is_the_host_resolved_tracing_endpoint() {
+fn otlp_url_is_the_host_resolved_tracing_endpoint() {
let mut config = Config::default();
- assert_eq!(ingestion_url(&config), "", "nothing resolved means no push");
- config.resolved_endpoints.tracing_ingest_url =
- Some("https://staging-api.tinyhumans.ai/telemetry/langfuse/ingestion".to_string());
+ assert_eq!(otlp_url(&config), "", "nothing resolved means no push");
+ config.resolved_endpoints.tracing_otlp_url =
+ Some("https://api.example.test/traces/otel/v1/traces".to_string());
assert_eq!(
- ingestion_url(&config),
- "https://staging-api.tinyhumans.ai/telemetry/langfuse/ingestion"
+ otlp_url(&config),
+ "https://api.example.test/traces/otel/v1/traces"
);
}
#[test]
-fn environment_derivation_from_backend_base() {
+fn environment_derivation_follows_the_resolved_bucket() {
+ let staging = config_resolved_as("staging");
+ let prod = config_resolved_as("production");
assert_eq!(
- environment_for_base("https://staging-api.tinyhumans.ai"),
+ environment_for_base(&staging, "https://staging.example.test"),
"staging"
);
- assert_eq!(environment_for_base("http://localhost:5000"), "development");
- assert_eq!(environment_for_base("http://127.0.0.1:5000"), "development");
assert_eq!(
- environment_for_base("https://api.tinyhumans.ai"),
+ environment_for_base(&prod, "https://api.example.test"),
"production"
);
+ for local in ["http://localhost:5000", "http://127.0.0.1:5000"] {
+ assert_eq!(
+ environment_for_base(&Config::default(), local),
+ "development"
+ );
+ }
}
-/// A hostname that merely *contains* `staging` is not ours. The classifier
-/// gates whether a live session token leaves the process, so anything it
-/// cannot positively recognise has to land on `external` — which does
-/// not push.
+/// With no host registered nothing resolves a hosted bucket, so every
+/// non-local origin is external and does not push.
#[test]
-fn a_lookalike_staging_host_is_external_not_staging() {
- for base in [
- // The substring match this replaced classified all of these as
- // staging, and `push_allowed` would then have let them through.
- "https://staging-attacker.invalid",
- "https://staging.evil.example",
- "http://staging-api.tinyhumans.ai.evil.example",
- // Right domain, wrong label position.
- "https://api-staging-mirror.tinyhumans.ai",
- // A public IP literal is never a deployment of ours.
- "https://93.184.216.34",
- // Never send a session bearer to a public backend over plaintext.
- "http://api.tinyhumans.ai",
- ] {
- let environment = environment_for_base(base);
- assert_eq!(
- environment, "external",
- "{base} must classify as external, got {environment}"
- );
- assert!(!push_allowed(environment), "{base} must not be pushable");
+fn without_a_registered_host_every_remote_origin_is_external() {
+ let config = Config::default();
+ for base in ["https://api.example.test", "https://staging.example.test"] {
+ assert_eq!(environment_for_base(&config, base), "external");
}
}
+/// A plaintext or unrecognised bucket never pushes, even when the host
+/// resolved a hosted bucket for its own control plane.
+#[test]
+fn a_resolved_bucket_does_not_unlock_plaintext_or_unknown_buckets() {
+ let prod = config_resolved_as("production");
+ assert_eq!(
+ environment_for_base(&prod, "http://api.example.test"),
+ "external"
+ );
+ assert_eq!(
+ environment_for_base(&config_resolved_as("preview"), "https://api.example.test"),
+ "external"
+ );
+}
+
/// The local buckets the substring form missed. An IPv6 loopback backend
/// is an ordinary local setup, and before the parse it classified as
/// external — so turning the push gate on would have silently stopped
@@ -105,7 +120,7 @@ fn local_backends_are_development_including_ipv6_and_private_ranges() {
"http://api.localhost:5000",
"http://0.0.0.0:5000",
] {
- let environment = environment_for_base(base);
+ let environment = environment_for_base(&Config::default(), base);
assert_eq!(
environment, "development",
"{base} must classify as development, got {environment}"
diff --git a/crates/openhuman-core/src/agent/progress_tracing/langfuse_trace_fields_tests.rs b/crates/openhuman-core/src/agent/progress_tracing/langfuse_trace_fields_tests.rs
index 8fa13a538f..34bc35cd4d 100644
--- a/crates/openhuman-core/src/agent/progress_tracing/langfuse_trace_fields_tests.rs
+++ b/crates/openhuman-core/src/agent/progress_tracing/langfuse_trace_fields_tests.rs
@@ -1,13 +1,13 @@
use super::*;
/// An unparseable base is the fail-closed default rather than a panic or a
-/// pushable bucket. `ingestion_url` returns a non-URL placeholder when no
+/// pushable bucket. `otlp_url` returns a non-URL placeholder when no
/// backend host resolves.
#[test]
fn an_unparseable_base_is_external() {
for base in ["", "not a url", "/api/v1/ingestion"] {
assert_eq!(
- environment_for_base(base),
+ environment_for_base(&Config::default(), base),
"external",
"{base:?} must fail closed"
);
diff --git a/crates/openhuman-tinyhumans/src/hosted/client.rs b/crates/openhuman-tinyhumans/src/hosted/client.rs
index ea981b33f9..6c44da60b5 100644
--- a/crates/openhuman-tinyhumans/src/hosted/client.rs
+++ b/crates/openhuman-tinyhumans/src/hosted/client.rs
@@ -30,7 +30,7 @@
//! phrases, budget exhaustion) keep matching them.
use crate::backend::url::effective_backend_api_url;
-use crate::transport::{BackendTransport, TransportProfile};
+use crate::transport::TransportProfile;
use openhuman_embed::__host::config::Config;
use openhuman_embed::__host::core::observability::{
contains_transient_transport_phrase, is_transient_http_status_code, API_KEY_REJECTED_PREFIX,
@@ -40,7 +40,6 @@ use openhuman_embed::__host::security::credentials::session_support::{
resolve_backend_credential, BackendCredential,
};
use serde_json::Value;
-use std::sync::Arc;
use tinyhumans_sdk::{Error as SdkError, TinyHumansClient};
const LOG_PREFIX: &str = "[hosted][client]";