@@ -111,22 +111,26 @@ where
111111 let mut dropped_p0_spans = 0 ;
112112
113113 traces. retain_mut ( |chunk| {
114+ // ErrorSampler
115+ if chunk. iter ( ) . any ( |s| s. error == 1 ) {
116+ // We send chunks containing an error
117+ return true ;
118+ }
119+
120+ // PrioritySampler and NoPrioritySampler
121+ let chunk_priority = chunk
122+ . iter ( )
123+ . find_map ( |s| s. metrics . get ( SAMPLING_PRIORITY_KEY ) ) ;
124+ if chunk_priority. is_none_or ( |p| * p > 0.0 ) {
125+ // We send chunks with positive priority or no priority
126+ return true ;
127+ }
128+
129+ // SingleSpanSampler and AnalyzedSpansSampler
114130 // List of spans to keep even if the chunk is dropped
115131 let mut sampled_indexes = Vec :: new ( ) ;
116132 for ( index, span) in chunk. iter ( ) . enumerate ( ) {
117- // ErrorSampler
118- if span. error == 1 {
119- // We send chunks containing an error
120- return true ;
121- }
122- // PrioritySampler and NoPrioritySampler
123- let priority = span. metrics . get ( SAMPLING_PRIORITY_KEY ) ;
124- if has_top_level ( span) && ( priority. is_none ( ) || priority. is_some_and ( |p| * p > 0.0 ) ) {
125- // We send chunks with positive priority or no priority
126- return true ;
127- }
128- // SingleSpanSampler and AnalyzedSpansSampler
129- else if span
133+ if span
130134 . metrics
131135 . get ( SAMPLING_SINGLE_SPAN_MECHANISM )
132136 . is_some_and ( |m| * m == 8.0 )
@@ -293,6 +297,27 @@ mod tests {
293297 ..Default :: default ( )
294298 } ,
295299 ] ;
300+ let chunk_with_multiple_top_level = vec ! [
301+ SpanBytes {
302+ span_id: 1 ,
303+ metrics: HashMap :: from( [
304+ ( SAMPLING_PRIORITY_KEY . into( ) , -1.0 ) ,
305+ ( TRACER_TOP_LEVEL_KEY . into( ) , 1.0 ) ,
306+ ] ) ,
307+ ..Default :: default ( )
308+ } ,
309+ SpanBytes {
310+ span_id: 2 ,
311+ parent_id: 1 ,
312+ ..Default :: default ( )
313+ } ,
314+ SpanBytes {
315+ span_id: 4 ,
316+ parent_id: 3 ,
317+ metrics: HashMap :: from( [ ( TRACER_TOP_LEVEL_KEY . into( ) , 1.0 ) ] ) ,
318+ ..Default :: default ( )
319+ } ,
320+ ] ;
296321 let chunk_with_error = vec ! [
297322 SpanBytes {
298323 span_id: 1 ,
@@ -346,6 +371,7 @@ mod tests {
346371 ( chunk_with_priority, 2 ) ,
347372 ( chunk_with_null_priority, 0 ) ,
348373 ( chunk_without_priority, 2 ) ,
374+ ( chunk_with_multiple_top_level, 0 ) ,
349375 ( chunk_with_error, 2 ) ,
350376 ( chunk_with_a_single_span, 1 ) ,
351377 ( chunk_with_analyzed_span, 1 ) ,
0 commit comments