Skip to content

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

fix(flows): export flow traces over Langfuse v4 OTLP

Steven Enamakeldf51aef4dcc1
diff --git a/crates/openhuman-core/src/flows/tinyflows/langfuse_export.rs b/crates/openhuman-core/src/flows/tinyflows/langfuse_export.rs
index 414dd7523a..b9033a3488 100644
--- a/crates/openhuman-core/src/flows/tinyflows/langfuse_export.rs
+++ b/crates/openhuman-core/src/flows/tinyflows/langfuse_export.rs
@@ -4,26 +4,30 @@
//! this module the run's durable [`GraphObservation`] slice (captured by the
//! per-run in-memory journal that `tinyflows`' journaled entry points fill)
//! and it exports the run as one Langfuse trace via the backend's Langfuse
-//! proxy route, `/telemetry/langfuse/ingestion`.
+//! OTLP proxy route, `/telemetry/langfuse/otel/v1/traces` (Langfuse v4; the
+//! legacy `/telemetry/langfuse/ingestion` batch path is not used for traces).
//!
-//! The batch is built by `tinyagents`' [`GraphLangfuseExporter`], which turns
+//! The trace is built by `tinyagents`' [`GraphLangfuseExporter`], which turns
//! each superstep and node into a timed span and stamps the Langfuse **Agent
//! Graph view** keys (`langgraph_node` / `langgraph_step`) on node spans, so
-//! the Langfuse UI can render the flow run as a graph. A host span-metadata
+//! the Langfuse UI can render the flow run as a graph, then projects it to
+//! v4 OTLP: trace name, session, tags, release and flow metadata ride on every
+//! span, since v4 filters observations directly. A host span-metadata
//! injector additionally stamps `flow_id` on every span for filtering.
//!
//! Transport mirrors the agent-turn tracing path
//! (`agent::progress_tracing::otlp::push_spans`): the endpoint is derived
//! from the **current backend hostname** (`effective_backend_api_url`), auth
//! is the live OpenHuman session bearer (the backend injects the real
-//! Langfuse keys server-side), the send is capped at 10s, `207 Multi-Status`
-//! is tolerated, and every failure is logged and swallowed — exporting is
-//! best-effort and never fails the run. Gated on
+//! Langfuse keys server-side, stamps the authenticated user on every span and
+//! adds `x-langfuse-ingestion-version: 4`), the send is capped at 10s, a
+//! partial OTLP rejection counts as a failure, and every failure is logged and
+//! swallowed — exporting is best-effort and never fails the run. Gated on
//! `observability.share_usage_data`.
use std::time::Duration;
-use serde_json::{json, Map};
+use serde_json::{json, Map, Value};
use tinyagents_graph::{GraphLangfuseExporter, GraphObservation};
use tinyagents_harness::{LangfuseAuth, LangfuseClient, LangfuseTraceConfig};
use tinyflows::engine::GraphObservation as FlowObservation;
@@ -34,9 +38,12 @@ use crate::security::credentials::session_support::direct_backend_credential;
use tinyflows_catalog::FlowRunTrigger;
const LOG_TARGET: &str = "flows::langfuse";
-/// Backend proxy route for Langfuse ingestion (relative to the backend
-/// origin). The backend authenticates the session JWT, injects the Langfuse
-/// project keys, and forwards to Langfuse's real `/api/public/ingestion`.
+/// Backend proxy route for legacy Langfuse ingestion (relative to the backend
+/// origin). Only the client's base: [`LangfuseClient::otlp_endpoint`] derives
+/// the OTLP route `/telemetry/langfuse/otel/v1/traces` beside it, which is
+/// where flow traces go. The backend authenticates the session JWT, injects
+/// the Langfuse project keys, and forwards to Langfuse's
+/// `/api/public/otel/v1/traces`.
const INGESTION_PATH: &str = "/telemetry/langfuse/ingestion";
/// Cap the push so a slow/hung Langfuse never stalls run teardown (same
/// posture as the agent-turn exporter).
@@ -106,6 +113,21 @@ fn build_flow_exporter(client: LangfuseClient, flow_id: &str) -> GraphLangfuseEx
})
}
+/// The Langfuse v4 OTLP requests for one flow run, under the product's
+/// `service.name` (the same one agent-turn traces use).
+fn flow_otlp_requests(
+ exporter: &GraphLangfuseExporter,
+ trace: LangfuseTraceConfig,
+ observations: &[GraphObservation],
+) -> tinyagents_harness::error::Result<Vec<Value>> {
+ exporter.build_otlp_requests(trace, observations, flow_service_name())
+}
+
+/// The OTLP `service.name` for flow traces.
+fn flow_service_name() -> &'static str {
+ crate::agent::progress_tracing::export_brand().product
+}
+
/// Exports one settled flow run to Langfuse as a single trace. Best-effort:
/// every failure path logs a `[flows]`-prefixed warning and returns — a
/// Langfuse outage can never fail or delay-fail the run. No-op when
@@ -196,15 +218,15 @@ pub async fn export_flow_run_trace(
status = %status,
trigger = %trigger.as_str(),
observation_count,
- endpoint = %exporter.endpoint(),
+ endpoint = %exporter.client().otlp_endpoint(),
"[flows] pushing flow run trace to Langfuse"
);
- // `send_observations` already tolerates 207 Multi-Status; the outer
+ // `send_observations_otlp` fails on a partial OTLP rejection; the outer
// timeout caps a hung connection the same way the agent exporter does.
match tokio::time::timeout(
PUSH_TIMEOUT,
- exporter.send_observations(trace, &observations),
+ exporter.send_observations_otlp(trace, &observations, flow_service_name()),
)
.await
{