@@ -89,6 +89,10 @@ def span_event(self, settings, base_attrs=None, parent_guid=None, attr_class=dic
8989 if i_attrs .get ("nr.entryPoint" ):
9090 ct_processing_time [0 ] += (time .time () - start_time )
9191 return [i_attrs , u_attrs , {}] if settings .distributed_tracing .minimize_attributes .enabled else [i_attrs , u_attrs , a_attrs ]
92+ # If this is the an LLM node, always return it.
93+ if a_attrs .get ("llm" ):
94+ ct_processing_time [0 ] += (time .time () - start_time )
95+ return [i_attrs , u_attrs , {"llm" : True }] if settings .distributed_tracing .minimize_attributes .enabled else [i_attrs , u_attrs , a_attrs ]
9296 # If the span is not an exit span, skip it by returning None.
9397 if not exit_span_attrs_present :
9498 ct_processing_time [0 ] += (time .time () - start_time )
@@ -104,13 +108,15 @@ def span_event(self, settings, base_attrs=None, parent_guid=None, attr_class=dic
104108 new_exit_span = span_attrs not in ct_exit_spans
105109 # If this is a new exit span, add it to the known ct_exit_spans and return it.
106110 if new_exit_span :
107- ct_exit_spans [span_attrs ] = self .ids
111+ ct_exit_spans [span_attrs ] = [ self .ids , i_attrs ]
108112 ct_processing_time [0 ] += (time .time () - start_time )
109113 return [i_attrs , u_attrs , a_minimized_attrs ] if settings .distributed_tracing .minimize_attributes .enabled else [i_attrs , u_attrs , a_attrs ]
110114 # If this is an exit span we've already seen, add it's guid to the list
111115 # of ids on the seen span and return None.
112116 # For now add ids to user attributes list
113- ct_exit_spans [span_attrs ].append (self .guid )
117+ ct_exit_spans [span_attrs ][0 ].append (self .guid )
118+ ct_exit_spans [span_attrs ][1 ]["duration" ] += self .duration
119+
114120 ct_processing_time [0 ] += (time .time () - start_time )
115121 return None
116122 elif settings .distributed_tracing .minimize_attributes .enabled :
@@ -125,7 +131,9 @@ def span_events(self, settings, base_attrs=None, parent_guid=None, attr_class=di
125131 parent_id = parent_guid
126132 if span : # span will be None if the span is an inprocess span or repeated exit span.
127133 yield span
128- parent_id = self .guid
134+ # Compressed spans are always reparented onto the entry span.
135+ if not settings .distributed_tracing .unique_spans .enabled or span [0 ].get ("nr.entryPoint" ):
136+ parent_id = self .guid
129137 for child in self .children :
130138 for event in child .span_events ( # noqa: UP028
131139 settings , base_attrs = base_attrs , parent_guid = parent_id , attr_class = attr_class , ct_exit_spans = ct_exit_spans , ct_processing_time = ct_processing_time
0 commit comments