Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix(ops_trace_manager): Adds app_id to TraceTask initialization (#20461)

-LAN-f2e0d161a19e
diff --git a/api/core/ops/langfuse_trace/langfuse_trace.py b/api/core/ops/langfuse_trace/langfuse_trace.py
index 120c36f53d2..fa1c6b45571 100644
--- a/api/core/ops/langfuse_trace/langfuse_trace.py
+++ b/api/core/ops/langfuse_trace/langfuse_trace.py
@@ -32,6 +32,7 @@ from core.repositories import SQLAlchemyWorkflowNodeExecutionRepository
from core.workflow.nodes.enums import NodeType
from extensions.ext_database import db
from models import Account, App, EndUser, WorkflowNodeExecutionTriggeredFrom
+from models.account import TenantAccountJoin
logger = logging.getLogger(__name__)
@@ -130,6 +131,12 @@ class LangFuseDataTrace(BaseTraceInstance):
service_account = session.query(Account).filter(Account.id == app.created_by).first()
if not service_account:
raise ValueError(f"Creator account with id {app.created_by} not found for app {app_id}")
+ current_tenant = (
+ session.query(TenantAccountJoin).filter_by(account_id=service_account.id, current=True).first()
+ )
+ if not current_tenant:
+ raise ValueError(f"Current tenant not found for account {service_account.id}")
+ service_account.set_tenant_id(current_tenant.tenant_id)
workflow_node_execution_repository = SQLAlchemyWorkflowNodeExecutionRepository(
session_factory=session_factory,
diff --git a/api/core/ops/ops_trace_manager.py b/api/core/ops/ops_trace_manager.py
index addf164e6fd..dc4cfc48dbb 100644
--- a/api/core/ops/ops_trace_manager.py
+++ b/api/core/ops/ops_trace_manager.py
@@ -487,6 +487,7 @@ class TraceTask:
"file_list": file_list,
"triggered_from": workflow_run.triggered_from,
"user_id": user_id,
+ "app_id": workflow_run.app_id,
}
workflow_trace_info = WorkflowTraceInfo(