瀏覽代碼

fix: sending app trace data to other app trace provider (#6931)

tags/0.6.16
takatost 1 年之前
父節點
當前提交
bcd7c8e921
No account linked to committer's email address
共有 2 個文件被更改,包括 7 次插入25 次删除
  1. 6
    22
      api/core/ops/ops_trace_manager.py
  2. 1
    3
      api/tasks/ops_trace_task.py

+ 6
- 22
api/core/ops/ops_trace_manager.py 查看文件

def get_ops_trace_instance( def get_ops_trace_instance(
cls, cls,
app_id: Optional[Union[UUID, str]] = None, app_id: Optional[Union[UUID, str]] = None,
message_id: Optional[str] = None,
conversation_id: Optional[str] = None
): ):
""" """
Get ops trace through model config Get ops trace through model config
:param app_id: app_id :param app_id: app_id
:param message_id: message_id
:param conversation_id: conversation_id
:return: :return:
""" """
if conversation_id is not None:
conversation_data: Conversation = db.session.query(Conversation).filter(
Conversation.id == conversation_id
).first()
if conversation_data:
app_id = conversation_data.app_id

if message_id is not None:
record: Message = db.session.query(Message).filter(Message.id == message_id).first()
app_id = record.app_id

if isinstance(app_id, UUID): if isinstance(app_id, UUID):
app_id = str(app_id) app_id = str(app_id)


self.kwargs = kwargs self.kwargs = kwargs
self.file_base_url = os.getenv("FILES_URL", "http://127.0.0.1:5001") self.file_base_url = os.getenv("FILES_URL", "http://127.0.0.1:5001")


self.app_id = None

def execute(self): def execute(self):
return self.preprocess() return self.preprocess()






class TraceQueueManager: class TraceQueueManager:
def __init__(self, app_id=None, conversation_id=None, message_id=None):
def __init__(self, app_id=None):
global trace_manager_timer global trace_manager_timer


self.app_id = app_id self.app_id = app_id
self.conversation_id = conversation_id
self.message_id = message_id
self.trace_instance = OpsTraceManager.get_ops_trace_instance(app_id, conversation_id, message_id)
self.trace_instance = OpsTraceManager.get_ops_trace_instance(app_id)
self.flask_app = current_app._get_current_object() self.flask_app = current_app._get_current_object()
if trace_manager_timer is None: if trace_manager_timer is None:
self.start_timer() self.start_timer()
global trace_manager_queue global trace_manager_queue
try: try:
if self.trace_instance: if self.trace_instance:
trace_task.app_id = self.app_id
trace_manager_queue.put(trace_task) trace_manager_queue.put(trace_task)
except Exception as e: except Exception as e:
logging.debug(f"Error adding trace task: {e}") logging.debug(f"Error adding trace task: {e}")
for task in tasks: for task in tasks:
trace_info = task.execute() trace_info = task.execute()
task_data = { task_data = {
"app_id": self.app_id,
"conversation_id": self.conversation_id,
"message_id": self.message_id,
"app_id": task.app_id,
"trace_info_type": type(trace_info).__name__, "trace_info_type": type(trace_info).__name__,
"trace_info": trace_info.model_dump() if trace_info else {}, "trace_info": trace_info.model_dump() if trace_info else {},
} }

+ 1
- 3
api/tasks/ops_trace_task.py 查看文件



trace_info = tasks_data.get('trace_info') trace_info = tasks_data.get('trace_info')
app_id = tasks_data.get('app_id') app_id = tasks_data.get('app_id')
conversation_id = tasks_data.get('conversation_id')
message_id = tasks_data.get('message_id')
trace_info_type = tasks_data.get('trace_info_type') trace_info_type = tasks_data.get('trace_info_type')
trace_instance = OpsTraceManager.get_ops_trace_instance(app_id, conversation_id, message_id)
trace_instance = OpsTraceManager.get_ops_trace_instance(app_id)


if trace_info.get('message_data'): if trace_info.get('message_data'):
trace_info['message_data'] = Message.from_dict(data=trace_info['message_data']) trace_info['message_data'] = Message.from_dict(data=trace_info['message_data'])

Loading…
取消
儲存