Skip to content

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

fix(agent): handle missing trace context in langfuse and otlp exports

Steven Enamakel2cd6c9720bdf
diff --git a/crates/openhuman-core/src/agent/progress_tracing/langfuse/journal_export.rs b/crates/openhuman-core/src/agent/progress_tracing/langfuse/journal_export.rs
index 96e6f8d70a..7bf6ea119d 100644
--- a/crates/openhuman-core/src/agent/progress_tracing/langfuse/journal_export.rs
+++ b/crates/openhuman-core/src/agent/progress_tracing/langfuse/journal_export.rs
@@ -11,7 +11,7 @@ use tinyagents_harness::observability::{AgentObservation, LangfuseClient, Langfu
use tinyagents_session::run_ledger::RunTelemetry;
use crate::config::Config;
-use crate::security::credentials::session_support::require_live_session_token;
+use crate::security::credentials::session_support::direct_backend_credential;
use super::ingestion_batch::{new_event_id, split_ingestion_batch, LANGFUSE_MAX_BATCH_EVENTS};
use super::TraceContext;
diff --git a/crates/openhuman-core/src/agent/progress_tracing/langfuse/span_export.rs b/crates/openhuman-core/src/agent/progress_tracing/langfuse/span_export.rs
index 3e8dad6a47..3c907f1866 100644
--- a/crates/openhuman-core/src/agent/progress_tracing/langfuse/span_export.rs
+++ b/crates/openhuman-core/src/agent/progress_tracing/langfuse/span_export.rs
@@ -6,7 +6,7 @@ use serde_json::{json, Map, Value};
use crate::api::jwt::bearer_authorization_value;
use crate::config::Config;
-use crate::security::credentials::session_support::require_live_session_token;
+use crate::security::credentials::session_support::direct_backend_credential;
use super::ingestion_batch::{iso_millis, new_event_id};
use super::{environment_for_base, ingestion_url, skip_push, LOG_TARGET, PUSH_TIMEOUT};
diff --git a/crates/openhuman-core/src/agent/progress_tracing/otlp.rs b/crates/openhuman-core/src/agent/progress_tracing/otlp.rs
index 036ab63faa..a3d36f6c63 100644
--- a/crates/openhuman-core/src/agent/progress_tracing/otlp.rs
+++ b/crates/openhuman-core/src/agent/progress_tracing/otlp.rs
@@ -9,7 +9,7 @@ use super::langfuse::{environment_for_base, ingestion_url, skip_push};
use super::types::{SpanKind, SpanStatus, TraceSpan};
use crate::api::jwt::bearer_authorization_value;
use crate::config::Config;
-use crate::security::credentials::session_support::require_live_session_token;
+use crate::security::credentials::session_support::direct_backend_credential;
// The backend JSON parser caps requests at 10 MiB. A generation can carry a
// 200 KiB structured prompt, so use a much smaller transport batch.
diff --git a/crates/openhuman-core/src/channels/bus/delivery.rs b/crates/openhuman-core/src/channels/bus/delivery.rs
index 3c239c1265..cf0c47434e 100644
--- a/crates/openhuman-core/src/channels/bus/delivery.rs
+++ b/crates/openhuman-core/src/channels/bus/delivery.rs
@@ -183,6 +183,28 @@ pub(super) async fn finalize_channel_reply(
}
}
+/// The session JWT the backend channel relay authenticates with, or `None`
+/// (logged at debug) when there is none to use: no TinyHumans connection, the
+/// user signed out while a relay message was in flight, the offline local
+/// session, or an API-key-only runtime (the relay binds a user session). All
+/// are user or build state, not faults, so nothing reaches Sentry.
+fn relay_session_token(config: &crate::config::Config, op: &str) -> Option<String> {
+ use crate::security::credentials::session_support::{
+ direct_backend_credential, BackendCredential,
+ };
+ match direct_backend_credential(config, "channel relay") {
+ Some(BackendCredential::Session(token)) => Some(token),
+ Some(BackendCredential::ApiKey(_)) => {
+ tracing::debug!("[channel-inbound] api-key runtime has no relay session — cannot {op}");
+ None
+ }
+ None => {
+ tracing::debug!("[channel-inbound] no hosted session — cannot {op}");
+ None
+ }
+ }
+}
+
/// Construct the REST client + session JWT shared by every outbound
/// channel call on this turn. Returns `None` and logs if either is
/// unavailable so the caller can bail quietly.
@@ -196,19 +218,7 @@ pub(super) async fn build_channel_client() -> Option<(crate::api::rest::BackendO
}
};
let api_url = crate::api::config::effective_backend_api_url(&config.api_url);
- let jwt = match crate::api::jwt::get_session_token(&config) {
- Ok(Some(t)) => t,
- Ok(None) => {
- // Signed out while an inbound relay message was in flight: user
- // state, not a fault — keep it out of Sentry.
- tracing::warn!("[channel-inbound] no session JWT — cannot send");
- return None;
- }
- Err(e) => {
- tracing::error!("[channel-inbound] failed to get session token: {}", e);
- return None;
- }
- };
+ let jwt = relay_session_token(&config, "send")?;
match crate::api::rest::BackendOAuthClient::new(&api_url) {
Ok(c) => Some((c, jwt)),
Err(e) => {
@@ -229,16 +239,8 @@ pub(super) async fn send_channel_reply(channel: &str, text: &str) {
};
let api_url = crate::api::config::effective_backend_api_url(&config.api_url);
- let jwt = match crate::api::jwt::get_session_token(&config) {
- Ok(Some(t)) => t,
- Ok(None) => {
- tracing::warn!("[channel-inbound] no session JWT — cannot reply");
- return;
- }
- Err(e) => {
- tracing::error!("[channel-inbound] failed to get session token: {}", e);
- return;
- }
+ let Some(jwt) = relay_session_token(&config, "reply") else {
+ return;
};
let client = match crate::api::rest::BackendOAuthClient::new(&api_url) {
diff --git a/crates/openhuman-core/src/flows/tinyflows/langfuse_export.rs b/crates/openhuman-core/src/flows/tinyflows/langfuse_export.rs
index f9967d63fe..574fc01685 100644
--- a/crates/openhuman-core/src/flows/tinyflows/langfuse_export.rs
+++ b/crates/openhuman-core/src/flows/tinyflows/langfuse_export.rs
@@ -31,7 +31,7 @@ use tinyflows::engine::GraphObservation as FlowObservation;
use crate::api::config::effective_backend_api_url;
use crate::config::Config;
use crate::flows::FlowRunTrigger;
-use crate::security::credentials::session_support::require_live_session_token;
+use crate::security::credentials::session_support::direct_backend_credential;
const LOG_TARGET: &str = "flows::langfuse";
/// Backend proxy route for Langfuse ingestion (relative to the backend
@@ -179,18 +179,18 @@ pub async fn export_flow_run_trace(
);
return;
}
- let token = match require_live_session_token(config) {
- Ok(token) => token,
- Err(err) => {
- tracing::warn!(
- target: LOG_TARGET,
- flow_id = %flow_id,
- error = %err,
- "[flows] langfuse export skipped: no live session token"
- );
- return;
- }
+ // No TinyHumans connection, or no usable credential (signed out, offline
+ // local session): a configured state — `direct_backend_credential` logs
+ // the reason at debug, and the export is skipped without a request.
+ let Some(credential) = direct_backend_credential(config, "flows langfuse export") else {
+ tracing::debug!(
+ target: LOG_TARGET,
+ flow_id = %flow_id,
+ "[flows] langfuse export skipped: hosted backend not available"
+ );
+ return;
};
+ let token = credential.into_secret();
let client = match LangfuseClient::new(url.clone(), LangfuseAuth::Bearer { token }) {
Ok(client) => client,
Err(err) => {