From 79e286dca9eb59cfb5684f13b4bfba5ecc301ccd Mon Sep 17 00:00:00 2001 From: Sushant Gautam Date: Tue, 13 Oct 2026 19:41:37 +0200 Subject: [PATCH] fix(chat): align tracing function and stub on top-level chat_id The OWUI filter sent chat_id inside body.metadata while the outlet path relied on context keys Open WebUI does not populate, so chats fell back to a random id per hop and spans never matched a stable session. Send chat_id at the body top level (both inlet and outlet) and have the stub prefer it. --- chat/openwebui_functions/studio_langfuse_capture.py | 3 +-- chat/pipelines_service.py | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/chat/openwebui_functions/studio_langfuse_capture.py b/chat/openwebui_functions/studio_langfuse_capture.py index 457d8d8..80d1db4 100644 --- a/chat/openwebui_functions/studio_langfuse_capture.py +++ b/chat/openwebui_functions/studio_langfuse_capture.py @@ -72,9 +72,9 @@ async def user_message(self, message, history, user_message, chat_id=None, __use return user_message payload = { "body": { + "chat_id": chat_id or str(uuid.uuid4()), "messages": [dict(m) for m in (history or [])] + [{"role": "user", "content": user_message}], "model": kwargs.get("model") or {}, - "metadata": {"chat_id": chat_id or str(uuid.uuid4())}, }, "user": self._user_payload(__user__), } @@ -100,7 +100,6 @@ async def after_chat_completion(self, content, context=None, __user__=None, **kw "body": { "chat_id": ctx.get("chat_id") or "local", "messages": messages, - "metadata": ctx.get("metadata") or {}, }, "user": self._user_payload(__user__), } diff --git a/chat/pipelines_service.py b/chat/pipelines_service.py index b785498..66e4717 100644 --- a/chat/pipelines_service.py +++ b/chat/pipelines_service.py @@ -112,7 +112,7 @@ def _get_langfuse(): def _chat_id(body: dict) -> str: metadata = body.get("metadata") or {} - chat_id = metadata.get("chat_id") or "local" + chat_id = body.get("chat_id") or metadata.get("chat_id") or "local" if chat_id == "local": session_id = metadata.get("session_id") chat_id = f"temporary-session-{session_id}" if session_id else str(uuid.uuid4())