@@ -953,8 +953,19 @@ def __init__(self, _id, signal_source, vtap_id, _type, protocol,
953953 # tcp_seq
954954 self .req_tcp_seq = req_tcp_seq
955955 self .resp_tcp_seq = resp_tcp_seq
956+ # trace_id, possible format: trace_id, trace_id_2
957+ if isinstance (trace_id , list ):
958+ self .trace_id = set (trace_id )
959+ elif isinstance (trace_id , set ):
960+ self .trace_id = trace_id
961+ elif isinstance (trace_id , str ) and trace_id :
962+ self .trace_id = {
963+ t .strip ()
964+ for t in trace_id .split (',' ) if t .strip ()
965+ }
966+ else :
967+ self .trace_id = set ()
956968 # span_id
957- self .trace_id = trace_id
958969 self .span_id = span_id
959970 self .parent_span_id = parent_span_id
960971 # x_request_id
@@ -1186,7 +1197,7 @@ def flow_field_conflict(cls, lhs: TraceInfo, rhs: TraceInfo) -> bool:
11861197 # payload 截断指的是:req_x/endpoint 从 payload 中某个位置获取信息
11871198 # 在 eBPF 位置获取了完整的包能解析;在 Packet 位置只取到了两个重组成功的 TCP Segment,刚好缺少需要解析的信息,于是解码有缺
11881199 if lhs .trace_id and rhs .trace_id :
1189- if not (set ( lhs .trace_id ) & set ( rhs .trace_id ) ):
1200+ if not (lhs .trace_id & rhs .trace_id ):
11901201 return True
11911202 # trace_id 相等,span_id 也相等或者都为空,返回 False
11921203 # 其余情况返回 True
@@ -1473,8 +1484,9 @@ def set_relate(cls,
14731484 for rti in related_trace_infos :
14741485 if trace_info ._id == rti ._id :
14751486 continue
1476- if trace_info .trace_id != rti .trace_id :
1487+ if not ( trace_info .trace_id & rti .trace_id ) :
14771488 # The span_id of different traces is likely to be the same.
1489+ # Use intersection to support spans carrying multiple trace_ids.
14781490 continue
14791491 # span_id
14801492 if trace_info .span_id in [rti .span_id , rti .parent_span_id ]:
@@ -2562,7 +2574,7 @@ def allow_merge_async_flow(flow: dict) -> bool:
25622574 return False
25632575 if not flow ['is_async' ]:
25642576 return False
2565- if flow ['trace_id' ] == "" :
2577+ if not flow ['trace_id' ]:
25662578 return False
25672579 return True
25682580
0 commit comments