@@ -497,21 +497,25 @@ async def trace_l7_flow(
497497 time_filter , base_filter , max_iteration , network_delay_us ,
498498 app_spans_from_api )
499499
500- if len (l7_flow_ids ) == 0 :
500+ if len (l7_flow_ids ) == 0 and len ( app_spans_from_external ) == 0 :
501501 return {}
502502
503503 # 查询会获取这些 _id 对应的完整 l7_flow_log 信息。
504504 # 通过 RETURN_FIELDS 确定需要返回哪些字段(精简有用的返回信息)
505505 return_fields = RETURN_FIELDS
506506 if self .has_attributes :
507507 return_fields .append ("attribute" )
508- l7_flows = await self .query_all_flows (time_filter , l7_flow_ids ,
509- return_fields )
510- if type (l7_flows ) != DataFrame or l7_flows .empty :
511- # 几乎不可能发生没有 l7_flows 但有 app_spans_from_apm 的情况
512- # 实际上几乎不可能发生没有 l7_flows 的情况,因为至少包含初始 flow
513- return {}
514- l7_flows .rename (columns = {'_id_str' : '_id' }, inplace = True )
508+ l7_flows = pd .DataFrame ()
509+ if len (l7_flow_ids ) > 0 :
510+ l7_flows = await self .query_all_flows (time_filter , l7_flow_ids ,
511+ return_fields )
512+ if type (l7_flows ) != DataFrame or l7_flows .empty :
513+ # 一般不可能发生没有 l7_flows 但有 app_spans_from_external 的情况
514+ # 实际上几乎不可能发生没有 l7_flows 的情况,因为至少包含初始 flow
515+ # 但由于 tracing_completion api 也调用此处追踪逻辑,接口可能传入不存在的 trace_id
516+ # 所以这里兼容 len(l7_flow_ids)=0 场景,仅对: 当 len(l7_flow_ids)>0 但 `query_all_flows` 为空时返回
517+ return {}
518+ l7_flows .rename (columns = {'_id_str' : '_id' }, inplace = True )
515519
516520 # 将外部 APM 查询到的 Span 与数据库中的 Span 结果进行合并
517521 l7_flows = self .concat_l7_flow_log_dataframe (
0 commit comments