diff --git a/api/db/services/dialog_service.py b/api/db/services/dialog_service.py index ed178434d..9935827be 100644 --- a/api/db/services/dialog_service.py +++ b/api/db/services/dialog_service.py @@ -296,10 +296,14 @@ async def async_chat(dialog, messages, stream=True, **kwargs): langfuse_keys = TenantLangfuseService.filter_by_tenant(tenant_id=dialog.tenant_id) if langfuse_keys: langfuse = Langfuse(public_key=langfuse_keys.public_key, secret_key=langfuse_keys.secret_key, host=langfuse_keys.host) - if langfuse.auth_check(): - langfuse_tracer = langfuse - trace_id = langfuse_tracer.create_trace_id() - trace_context = {"trace_id": trace_id} + try: + if langfuse.auth_check(): + langfuse_tracer = langfuse + trace_id = langfuse_tracer.create_trace_id() + trace_context = {"trace_id": trace_id} + except Exception: + # Skip langfuse tracing if connection fails + pass check_langfuse_tracer_ts = timer() kbs, embd_mdl, rerank_mdl, chat_mdl, tts_mdl = get_models(dialog) diff --git a/api/db/services/tenant_llm_service.py b/api/db/services/tenant_llm_service.py index 43f9107b2..5bd663734 100644 --- a/api/db/services/tenant_llm_service.py +++ b/api/db/services/tenant_llm_service.py @@ -392,7 +392,11 @@ class LLM4Tenant: self.langfuse = None if langfuse_keys: langfuse = Langfuse(public_key=langfuse_keys.public_key, secret_key=langfuse_keys.secret_key, host=langfuse_keys.host) - if langfuse.auth_check(): - self.langfuse = langfuse - trace_id = self.langfuse.create_trace_id() - self.trace_context = {"trace_id": trace_id} + try: + if langfuse.auth_check(): + self.langfuse = langfuse + trace_id = self.langfuse.create_trace_id() + self.trace_context = {"trace_id": trace_id} + except Exception: + # Skip langfuse tracing if connection fails + pass