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: langsmith message_trace end_user_data session_id error (#5759)

Joef637ae4794a0
diff --git a/api/core/ops/langfuse_trace/langfuse_trace.py b/api/core/ops/langfuse_trace/langfuse_trace.py
index 06eb3e2f438..5b5d5def1bd 100644
--- a/api/core/ops/langfuse_trace/langfuse_trace.py
+++ b/api/core/ops/langfuse_trace/langfuse_trace.py
@@ -215,7 +215,9 @@ class LangFuseDataTrace(BaseTraceInstance):
end_user_data: EndUser = db.session.query(EndUser).filter(
EndUser.id == message_data.from_end_user_id
).first()
- user_id = end_user_data.session_id
+ if end_user_data is not None:
+ user_id = end_user_data.session_id
+ metadata["user_id"] = user_id
trace_data = LangfuseTrace(
id=message_id,
diff --git a/api/core/ops/langsmith_trace/langsmith_trace.py b/api/core/ops/langsmith_trace/langsmith_trace.py
index 1dbda601edf..0fee076d55a 100644
--- a/api/core/ops/langsmith_trace/langsmith_trace.py
+++ b/api/core/ops/langsmith_trace/langsmith_trace.py
@@ -183,13 +183,15 @@ class LangSmithDataTrace(BaseTraceInstance):
message_id = message_data.id
user_id = message_data.from_account_id
+ metadata["user_id"] = user_id
+
if message_data.from_end_user_id:
end_user_data: EndUser = db.session.query(EndUser).filter(
EndUser.id == message_data.from_end_user_id
- ).first().session_id
- end_user_id = end_user_data.session_id
- metadata["end_user_id"] = end_user_id
- metadata["user_id"] = user_id
+ ).first()
+ if end_user_data is not None:
+ end_user_id = end_user_data.session_id
+ metadata["end_user_id"] = end_user_id
message_run = LangSmithRunModel(
input_tokens=trace_info.message_tokens,