mirror of
https://github.com/langgenius/dify.git
synced 2026-09-24 23:22:26 +08:00
feat: support custom trace session id for Phoenix tracing (#37056)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
autofix-ci[bot]
parent
f9320b2c91
commit
c8abb11bf0
@@ -5,6 +5,7 @@ import os
|
||||
import queue
|
||||
import threading
|
||||
import time
|
||||
from collections.abc import Mapping
|
||||
from datetime import timedelta
|
||||
from typing import TYPE_CHECKING, Any, TypedDict
|
||||
from uuid import UUID, uuid4
|
||||
@@ -64,6 +65,11 @@ def _dump_parent_trace_context(parent_trace_context: Any) -> dict[str, str] | No
|
||||
return None
|
||||
|
||||
|
||||
def _get_trace_session_id(kwargs: Mapping[str, Any]) -> str | None:
|
||||
value = kwargs.get("trace_session_id")
|
||||
return value if isinstance(value, str) and value else None
|
||||
|
||||
|
||||
class _AppTracingConfig(TypedDict, total=False):
|
||||
enabled: bool
|
||||
tracing_provider: str | None
|
||||
@@ -873,6 +879,10 @@ class TraceTask:
|
||||
if dumped_parent_trace_context:
|
||||
metadata["parent_trace_context"] = dumped_parent_trace_context
|
||||
|
||||
trace_session_id = _get_trace_session_id(self.kwargs)
|
||||
if trace_session_id:
|
||||
metadata["trace_session_id"] = trace_session_id
|
||||
|
||||
workflow_trace_info = WorkflowTraceInfo(
|
||||
trace_id=self.trace_id,
|
||||
workflow_data=workflow_run.to_dict(),
|
||||
@@ -956,6 +966,10 @@ class TraceTask:
|
||||
if node_execution_id := kwargs.get("node_execution_id"):
|
||||
metadata["node_execution_id"] = node_execution_id
|
||||
|
||||
trace_session_id = _get_trace_session_id(kwargs)
|
||||
if trace_session_id:
|
||||
metadata["trace_session_id"] = trace_session_id
|
||||
|
||||
message_tokens = message_data.message_tokens
|
||||
|
||||
message_trace_info = MessageTraceInfo(
|
||||
|
||||
Reference in New Issue
Block a user