Skip to content

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

feat(observability): export subagent journal traces as distinct traces

Steven Enamakelb6960b772a3c
diff --git a/crates/openhuman-core/src/agent/subagent_host/ops/graph/dispatch.rs b/crates/openhuman-core/src/agent/subagent_host/ops/graph/dispatch.rs
index 94adbefd79..b3d6e08155 100644
--- a/crates/openhuman-core/src/agent/subagent_host/ops/graph/dispatch.rs
+++ b/crates/openhuman-core/src/agent/subagent_host/ops/graph/dispatch.rs
@@ -92,6 +92,7 @@ pub(in super::super) async fn run_subagent_via_graph(
SubagentRunError,
> {
let (run_queue, message_run_queue) = queues;
+ let trace_session_group = run_context.thread_id.clone().or_else(|| thread_id.clone());
// One resolved thread identity drives every child-facing boundary. An
// explicit worker/task thread deliberately replaces the inherited parent;
// otherwise a child remains in its parent's conversation. Do this before
@@ -255,11 +256,39 @@ pub(in super::super) async fn run_subagent_via_graph(
// (they report via `Subagent*` events). Pass `false` for clarity.
defer_turn_completed_to_caller: false,
};
+ let child_journal_run_id = native_subagent
+ .as_ref()
+ .map(|native| native.config.run_id.as_str().to_string());
let run_result = match native_subagent {
Some(native) => turn_spec.run_with_native_subagent(native).await,
None => turn_spec.run().await,
};
+ // Preserve the existing detached child trace export. It is separately
+ // gated by the usage-sharing/auth configuration and reads this run's
+ // durable native journal, including for unobserved child turns.
+ if let (Some(config), Some(journal_run_id)) = (
+ config.filter(|config| config.observability.share_usage_data),
+ child_journal_run_id,
+ ) {
+ let config = config.clone();
+ let thread_id = trace_session_group.clone();
+ let agent_id = agent_id.to_string();
+ let task_id = task_id.to_string();
+ let dispatch = dispatch.clone();
+ tokio::spawn(async move {
+ crate::core::observability::progress_tracing::export_subagent_journal_trace(
+ &dispatch,
+ &config,
+ &journal_run_id,
+ thread_id.as_deref(),
+ &agent_id,
+ &task_id,
+ )
+ .await;
+ });
+ }
+
let mut outcome = match run_result {
Ok(outcome) => outcome,
Err(err) => {
diff --git a/crates/openhuman-core/src/core/observability/progress_tracing.rs b/crates/openhuman-core/src/core/observability/progress_tracing.rs
index b03cf986b6..c773d1e17a 100644
--- a/crates/openhuman-core/src/core/observability/progress_tracing.rs
+++ b/crates/openhuman-core/src/core/observability/progress_tracing.rs
@@ -16,4 +16,4 @@ pub(crate) fn export_brand() -> ExportBrand<'static> {
}
}
-pub(crate) use export::export_run_trace_from_journal;
+pub(crate) use export::{export_run_trace_from_journal, export_subagent_journal_trace};
diff --git a/crates/openhuman-core/src/core/observability/progress_tracing/export.rs b/crates/openhuman-core/src/core/observability/progress_tracing/export.rs
index a271b56ec9..07147659c6 100644
--- a/crates/openhuman-core/src/core/observability/progress_tracing/export.rs
+++ b/crates/openhuman-core/src/core/observability/progress_tracing/export.rs
@@ -13,6 +13,17 @@ use tinyagents_harness::observability::LangfuseClient;
const PUSH_TIMEOUT: Duration = Duration::from_secs(10);
+fn reject_partial_success(response: &serde_json::Value) -> Result<(), String> {
+ if response["partialSuccess"]["errorMessage"]
+ .as_str()
+ .is_some_and(|message| !message.is_empty())
+ {
+ Err("Langfuse OTLP proxy reported partial success".to_string())
+ } else {
+ Ok(())
+ }
+}
+
async fn push_spans(config: &Config, spans: &[TraceSpan]) -> Result<(), String> {
if spans.is_empty() {
return Ok(());
@@ -44,10 +55,11 @@ async fn push_spans(config: &Config, spans: &[TraceSpan]) -> Result<(), String>
)
.map_err(|_| "Langfuse OTLP proxy client could not be configured".to_string())?;
for payload in otlp_requests(spans, environment, &super::export_brand()) {
- tokio::time::timeout(PUSH_TIMEOUT, client.send_otlp(payload))
+ let response = tokio::time::timeout(PUSH_TIMEOUT, client.send_otlp(payload))
.await
.map_err(|_| "Langfuse OTLP proxy request timed out".to_string())?
.map_err(|_| "Langfuse OTLP proxy request failed".to_string())?;
+ reject_partial_success(&response)?;
}
Ok(())
}
@@ -199,6 +211,72 @@ pub(crate) async fn export_run_trace_from_journal(
export_run_trace(config, &spans).await;
}
+/// Export one completed child turn as a distinct trace in its conversation.
+/// The child journal retains its original parent/root lineage in trace metadata
+/// while its observations are rooted locally for span construction.
+pub(crate) async fn export_subagent_journal_trace(
+ ctx: &crate::core::runtime::DispatchCtx,
+ config: &Config,
+ journal_run_id: &str,
+ thread_id: Option<&str>,
+ agent_id: &str,
+ task_id: &str,
+) {
+ if !config.observability.share_usage_data {
+ return;
+ }
+ if !crate::backend::telemetry::langfuse::journal_push_ready(config) {
+ log::debug!("[agent-tracing] child trace export skipped: push not possible run_id={journal_run_id}");
+ return;
+ }
+ let observations = match crate::agent::tinyagents::journal::read_run_events(
+ ctx,
+ journal_run_id,
+ 0,
+ )
+ .await
+ {
+ Ok(observations) if !observations.is_empty() => observations,
+ Ok(_) => return,
+ Err(err) => {
+ log::warn!("[agent-tracing] child journal read failed run_id={journal_run_id}: {err}");
+ return;
+ }
+ };
+ let first = &observations[0];
+ let user_id = crate::security::credentials::identity::peek_credential_user_identity()
+ .and_then(|identity| identity.id.or(identity.email));
+ let trace_ctx = TraceContext::new(format!("subagent:{journal_run_id}"), user_id)
+ .with_session_group(thread_id.unwrap_or(task_id).to_string())
+ .with_agent_id(agent_id.to_string())
+ .with_channel_source("subagent".to_string())
+ .with_run_type(tinyagents_harness::observability::trace_export::RunType::Subagent)
+ .with_capture_content(config.observability.agent_tracing.capture_content)
+ .with_run_lineage(
+ Some(first.run_id.as_str().to_string()),
+ first.parent_run_id.as_ref().map(|id| id.as_str().to_string()),
+ Some(first.root_run_id.as_str().to_string()),
+ );
+ let rooted = tinyagents_harness::observability::trace_export::journal_export::root_subagent_observations(&observations);
+ let observation_root = first.run_id.clone();
+ let mut collector = tinyagents_harness::observability::trace_export::collector::SpanCollector::new(trace_ctx)
+ .with_observation_root(observation_root);
+ for observation in &rooted {
+ collector.record(observation);
+ }
+ let finished_at_ms = std::time::SystemTime::now()
+ .duration_since(std::time::UNIX_EPOCH)
+ .unwrap_or_default()
+ .as_millis()
+ .min(u128::from(u64::MAX)) as u64;
+ collector.finish(finished_at_ms);
+ let mut spans = collector.spans().to_vec();
+ tinyagents_harness::observability::trace_export::otlp::prepare_subagent_root(&mut spans);
+ if let Err(err) = push_spans(config, &spans).await {
+ log::warn!("[agent-tracing] child Langfuse OTLP push failed run_id={journal_run_id}: {err}");
+ }
+}
+
#[cfg(test)]
#[path = "export_tests.rs"]
mod tests;
diff --git a/crates/openhuman-core/src/core/observability/progress_tracing/export_tests.rs b/crates/openhuman-core/src/core/observability/progress_tracing/export_tests.rs
index 8429643aca..6aa0ce11a0 100644
--- a/crates/openhuman-core/src/core/observability/progress_tracing/export_tests.rs
+++ b/crates/openhuman-core/src/core/observability/progress_tracing/export_tests.rs
@@ -2,6 +2,28 @@ use super::*;
use std::collections::BTreeMap;
use tinyagents_harness::observability::trace_export::{SpanKind, SpanStatus};
+#[test]
+fn partial_success_error_message_is_rejected_even_when_rejected_count_is_zero() {
+ let response = serde_json::json!({
+ "partialSuccess": { "rejectedSpans": "0", "errorMessage": "receiver warning" }
+ });
+ assert!(reject_partial_success(&response).is_err());
+}
+
+#[test]
+fn partial_success_positive_rejected_count_is_rejected() {
+ let response = serde_json::json!({
+ "partialSuccess": { "rejectedSpans": "2", "errorMessage": "some spans rejected" }
+ });
+ assert!(reject_partial_success(&response).is_err());
+}
+
+#[test]
+fn empty_partial_success_response_is_accepted() {
+ assert!(reject_partial_success(&serde_json::json!({ "partialSuccess": {} })).is_ok());
+ assert!(reject_partial_success(&serde_json::json!({})).is_ok());
+}
+
#[tokio::test]
async fn external_backend_is_skipped_before_session_lookup() {
let mut config = Config::default();