move Langfuse to shared lng cluster, add trace instrumentation

This commit is contained in:
2026-04-16 00:56:39 -03:00
parent 004c4a9e65
commit 22c924d3b0
9 changed files with 119 additions and 151 deletions

View File

@@ -23,19 +23,25 @@ logging.basicConfig(
)
_langfuse_client = None
def _get_langfuse():
"""Lazy Langfuse client — returns None if not configured."""
"""Singleton Langfuse client — returns None if not configured."""
global _langfuse_client
if _langfuse_client is not None:
return _langfuse_client
try:
from api.config import get_settings
s = get_settings()
if not s.langfuse_public_key or not s.langfuse_secret_key:
return None
from langfuse import Langfuse
return Langfuse(
_langfuse_client = Langfuse(
public_key=s.langfuse_public_key,
secret_key=s.langfuse_secret_key,
host=s.langfuse_host,
)
return _langfuse_client
except Exception:
return None
@@ -175,7 +181,7 @@ async def trigger_fce(req: FCERequest):
logger.error("agent_error agent=fce run_id=%s error=%s", run_id, e)
finally:
if lf:
lf.shutdown()
lf.flush()
logger.info("agent_start agent=fce run_id=%s flight=%s", run_id, req.flight_id)
asyncio.create_task(_run())
@@ -223,7 +229,7 @@ async def trigger_handover(req: HandoverRequest):
logger.error("agent_error agent=handover run_id=%s error=%s", run_id, e)
finally:
if lf:
lf.shutdown()
lf.flush()
logger.info("agent_start agent=handover run_id=%s hubs=%s", run_id, req.hubs)
asyncio.create_task(_run())