@@ -106,12 +106,19 @@ def span_event(self, settings, base_attrs=None, parent_guid=None, attr_class=dic
106106 # ids is the list of span guids that share this unqiue exit span.
107107 a_minimized_attrs ["nr.ids" ] = []
108108 a_minimized_attrs ["nr.durations" ] = self .duration
109- ct_exit_spans [span_attrs ] = [a_minimized_attrs ]
109+ ct_exit_spans [span_attrs ] = [i_attrs , a_minimized_attrs ]
110110 return [i_attrs , {}, a_minimized_attrs ]
111111 # If this is an exit span we've already seen, add it's guid to the list
112112 # of ids on the seen span and return None.
113- ct_exit_spans [span_attrs ][0 ]["nr.ids" ].append (self .guid )
114- ct_exit_spans [span_attrs ][0 ]["nr.durations" ] += self .duration
113+ ct_exit_spans [span_attrs ][1 ]["nr.ids" ].append (self .guid )
114+ # Compute the new start and end time for all compressed spans and use
115+ # that to set the duration for all compressed spans.
116+ new_start_time = min (ct_exit_spans [span_attrs ][0 ]["timestamp" ], i_attrs ["timestamp" ])
117+ new_end_time = max (i_attrs ["timestamp" ]/ 1000 + self .duration , ct_exit_spans [span_attrs ][0 ]["timestamp" ]/ 1000 + ct_exit_spans [span_attrs ][1 ]["nr.durations" ])
118+ ct_exit_spans [span_attrs ][1 ]["nr.durations" ] = new_end_time - new_start_time
119+ # Reset the start time of the compressed span to be the start time of
120+ # the oldest compressed span.
121+ ct_exit_spans [span_attrs ][0 ]["timestamp" ] = new_start_time
115122 return None
116123
117124 def span_events (self , settings , base_attrs = None , parent_guid = None , attr_class = dict , partial_granularity_sampled = False , ct_exit_spans = None ):
0 commit comments