Skip to content

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

feat(observability): export tinyflows traces to langfuse

Steven Enamakel9043370ad287
diff --git a/crates/openhuman-core/src/flows/tinyflows/langfuse_export.rs b/crates/openhuman-core/src/flows/tinyflows/langfuse_export.rs
index 559ef60179..414dd7523a 100644
--- a/crates/openhuman-core/src/flows/tinyflows/langfuse_export.rs
+++ b/crates/openhuman-core/src/flows/tinyflows/langfuse_export.rs
@@ -27,6 +27,7 @@ use serde_json::{json, Map};
use tinyagents_graph::{GraphLangfuseExporter, GraphObservation};
use tinyagents_harness::{LangfuseAuth, LangfuseClient, LangfuseTraceConfig};
use tinyflows::engine::GraphObservation as FlowObservation;
+use tinyflows::observe::to_exporter_observations;
use crate::config::Config;
use crate::security::credentials::session_support::direct_backend_credential;
@@ -105,42 +106,6 @@ fn build_flow_exporter(client: LangfuseClient, flow_id: &str) -> GraphLangfuseEx
})
}
-/// Re-types the engine's observations for the exporter.
-///
-/// The engine now emits `tinyflows::engine::GraphObservation` — tinyflows
-/// vendored its state-graph runtime in PR #43 — while the Langfuse batch is
-/// still built by `tinyagents`' exporter, which names its own. The two types
-/// are the same shape (`tinyagents` is where tinyflows' copy came from) down
-/// to the `GraphEvent` payload, so this re-types through their shared serde
-/// representation rather than duplicating a 20-field mapping that would then
-/// have to be kept in step by hand.
-///
-/// An observation that fails to convert is **dropped, not fatal**: exporting
-/// is best-effort throughout this module, and losing one span from a trace is
-/// a better outcome than losing the trace. A drop is logged at `warn` because
-/// the only way it can happen is the two types drifting apart, which is worth
-/// hearing about — `re_typing_preserves_every_field` is the guard that should
-/// catch it first.
-fn to_exporter_observations(observations: &[FlowObservation]) -> Vec<GraphObservation> {
- observations
- .iter()
- .filter_map(|obs| {
- match serde_json::to_value(obs).and_then(serde_json::from_value::<GraphObservation>) {
- Ok(converted) => Some(converted),
- Err(err) => {
- tracing::warn!(
- target: LOG_TARGET,
- error = %err,
- "[flows] dropped an observation the exporter could not read — \
- tinyflows and tinyagents GraphObservation have drifted"
- );
- None
- }
- }
- })
- .collect()
-}
-
/// 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
@@ -210,7 +175,7 @@ pub async fn export_flow_run_trace(
}
};
- let observations = to_exporter_observations(journal_observations);
+ let observations = to_exporter_observations::<GraphObservation>(journal_observations);
if observations.is_empty() {
tracing::warn!(
target: LOG_TARGET,
diff --git a/crates/openhuman-core/src/flows/tinyflows/langfuse_export_tests.rs b/crates/openhuman-core/src/flows/tinyflows/langfuse_export_tests.rs
index f45d47ea07..3cae07ef79 100644
--- a/crates/openhuman-core/src/flows/tinyflows/langfuse_export_tests.rs
+++ b/crates/openhuman-core/src/flows/tinyflows/langfuse_export_tests.rs
@@ -230,7 +230,9 @@ async fn export_skips_api_key_credentials() {
);
}
-/// The re-typing hop is a serde round-trip between two independently
+/// The re-typing mapper itself lives (and is tested) in
+/// `tinyflows::observe`; this pins it against `tinyagents`' exporter type,
+/// which only the host sees. The hop is a serde round-trip between two independently
/// declared types, so nothing but a test notices when one of them grows,
/// renames, or re-tags a field: `to_exporter_observations` would start
/// silently dropping observations and the trace would quietly lose spans.
@@ -240,7 +242,7 @@ async fn export_skips_api_key_credentials() {
fn re_typing_preserves_every_field() {
let thread_id = "flow:flow-1:uuid-1";
let engine = sample_observations(thread_id);
- let converted = to_exporter_observations(&engine);
+ let converted: Vec<GraphObservation> = to_exporter_observations(&engine);
assert_eq!(
converted.len(),
diff --git a/crates/openhuman-core/src/flows/tinyflows/observability.rs b/crates/openhuman-core/src/flows/tinyflows/observability.rs
index 3b2a606099..496687157f 100644
--- a/crates/openhuman-core/src/flows/tinyflows/observability.rs
+++ b/crates/openhuman-core/src/flows/tinyflows/observability.rs
@@ -27,24 +27,14 @@
use std::sync::Arc;
-use tinyflows::observability::{ExecutionStep, Run, RunObserver, StepStatus};
+use tinyflows::observability::{ExecutionStep, Run, RunObserver};
+use tinyflows::observe::step_status_str;
use crate::config::Config;
use crate::core::bus::BUS;
use crate::core::events::DomainEvent;
use {crate::flows::upsert_flow_run_step, tinyflows_catalog::FlowRunStep};
-/// Maps a live [`StepStatus`] to the stable `"success"`/`"error"` string
-/// persisted on [`FlowRunStep::status`] and published on
-/// [`DomainEvent::FlowRunProgress`]. `StepStatus` does not derive `PartialEq`,
-/// so this matches rather than compares.
-fn step_status_str(status: &StepStatus) -> &'static str {
- match status {
- StepStatus::Success => "success",
- StepStatus::Error => "error",
- }
-}
-
/// The durable-run observer (issue G2): persists each finished step
/// incrementally and streams a progress event to the frontend.
///
diff --git a/crates/openhuman-core/src/flows/tinyflows/observability_tests.rs b/crates/openhuman-core/src/flows/tinyflows/observability_tests.rs
index 65f85640e2..b2263a8b1c 100644
--- a/crates/openhuman-core/src/flows/tinyflows/observability_tests.rs
+++ b/crates/openhuman-core/src/flows/tinyflows/observability_tests.rs
@@ -1,11 +1,5 @@
use super::*;
-#[test]
-fn step_status_maps_to_stable_strings() {
- assert_eq!(step_status_str(&StepStatus::Success), "success");
- assert_eq!(step_status_str(&StepStatus::Error), "error");
-}
-
/// The canvas's `.flow-node-running` pulse is bound to a `running` status
/// that only `on_step_start` can produce. Before it was implemented the
/// socket carried nothing but `success`/`failed`, so the pulse was