move irrop to def, upgrade Langfuse to v3 with ClickHouse, fix SDK v4 instrumentation

This commit is contained in:
2026-04-16 00:01:21 -03:00
parent 1b1b1383a1
commit 004c4a9e65
14 changed files with 131 additions and 156 deletions

View File

@@ -18,7 +18,7 @@ async def run_fce(
flight_id: str,
mcp: MCPMultiClient,
on_event: Any = None,
langfuse: Any = None,
lf: Any = None,
) -> dict:
run_start = time.time()
errors = []
@@ -67,10 +67,10 @@ async def run_fce(
async def _call(server, tool, args, is_live=False, timeout=15.0):
t = time.time()
ctx = langfuse.start_as_current_observation(
name=tool, as_type="tool",
input=args, metadata={"server": server, "is_live": is_live},
) if langfuse else None
ctx = lf.start_as_current_observation(
name=tool, as_type="tool", input=args,
metadata={"server": server, "is_live": is_live},
) if lf else None
if ctx:
ctx.__enter__()
try:
@@ -79,14 +79,14 @@ async def run_fce(
)
lat = int((time.time() - t) * 1000)
if ctx:
langfuse.update_current_span(output=result, metadata={"latency_ms": lat})
lf.update_current_span(output=result, metadata={"latency_ms": lat})
ctx.__exit__(None, None, None)
await emit("tool_call_end", tool=tool, latency_ms=lat, is_live=is_live)
return result
except asyncio.TimeoutError:
lat = int((time.time() - t) * 1000)
if ctx:
langfuse.update_current_span(output={"error": "timeout"}, level="ERROR")
lf.update_current_span(output={"error": "timeout"}, level="ERROR")
ctx.__exit__(None, None, None)
await emit("tool_call_error", tool=tool, error="timeout", latency_ms=lat)
errors.append(f"{tool}: timeout after {timeout}s")
@@ -94,7 +94,7 @@ async def run_fce(
except Exception as e:
lat = int((time.time() - t) * 1000)
if ctx:
langfuse.update_current_span(output={"error": str(e)}, level="ERROR")
lf.update_current_span(output={"error": str(e)}, level="ERROR")
ctx.__exit__(None, None, None)
await emit("tool_call_error", tool=tool, error=str(e), latency_ms=lat)
errors.append(f"{tool}: {e}")

View File

@@ -26,7 +26,7 @@ async def run_handover(
hubs: list[str] | None = None,
mcp: MCPMultiClient | None = None,
on_event: Any = None,
langfuse: Any = None,
lf: Any = None,
) -> dict:
target_hubs = hubs or ALL_HUBS
run_start = time.time()
@@ -45,10 +45,10 @@ async def run_handover(
async def _call(server, tool, args, is_live=False, timeout=15.0):
t = time.time()
ctx = langfuse.start_as_current_observation(
name=tool, as_type="tool",
input=args, metadata={"server": server, "is_live": is_live},
) if langfuse else None
ctx = lf.start_as_current_observation(
name=tool, as_type="tool", input=args,
metadata={"server": server, "is_live": is_live},
) if lf else None
if ctx:
ctx.__enter__()
try:
@@ -57,14 +57,14 @@ async def run_handover(
)
lat = int((time.time() - t) * 1000)
if ctx:
langfuse.update_current_span(output=result, metadata={"latency_ms": lat})
lf.update_current_span(output=result, metadata={"latency_ms": lat})
ctx.__exit__(None, None, None)
await emit("tool_call_end", tool=tool, latency_ms=lat, is_live=is_live)
return result
except asyncio.TimeoutError:
lat = int((time.time() - t) * 1000)
if ctx:
langfuse.update_current_span(output={"error": "timeout"}, level="ERROR")
lf.update_current_span(output={"error": "timeout"}, level="ERROR")
ctx.__exit__(None, None, None)
await emit("tool_call_error", tool=tool, error="timeout", latency_ms=lat)
errors.append(f"{tool}: timeout after {timeout}s")
@@ -72,7 +72,7 @@ async def run_handover(
except Exception as e:
lat = int((time.time() - t) * 1000)
if ctx:
langfuse.update_current_span(output={"error": str(e)}, level="ERROR")
lf.update_current_span(output={"error": str(e)}, level="ERROR")
ctx.__exit__(None, None, None)
await emit("tool_call_error", tool=tool, error=str(e), latency_ms=lat)
errors.append(f"{tool}: {e}")