@@ -171,88 +171,6 @@ def test_drop_isolated_per_bucket(
171171 assert record_lost_event_calls .count (("queue_overflow" , "span" , None , 1 )) == 1
172172
173173
174- def test_drop_after_global_max_reached (
175- sentry_init , capture_envelopes , capture_record_lost_event_calls , monkeypatch
176- ):
177- """New spans are dropped if the buffer reaches GLOBAL_MAX_BEFORE_DROP spans."""
178- monkeypatch .setattr (SpanBatcher , "GLOBAL_MAX_BEFORE_DROP" , 2 )
179- # set the time-based flush limit to something huge so that we're not flushing
180- # prematurely
181- monkeypatch .setattr (SpanBatcher , "FLUSH_WAIT_TIME" , 100000 )
182-
183- sentry_init (
184- traces_sample_rate = 1.0 ,
185- trace_lifecycle = "stream" ,
186- )
187-
188- envelopes = capture_envelopes ()
189- record_lost_event_calls = capture_record_lost_event_calls ()
190-
191- with sentry_sdk .traces .start_span (name = "span 1" ):
192- pass
193- with sentry_sdk .traces .start_span (name = "span 2" ):
194- pass
195- with sentry_sdk .traces .start_span (name = "span 3" ):
196- pass
197-
198- sentry_sdk .traces .new_trace ()
199- with sentry_sdk .traces .start_span (name = "span 4" ):
200- pass
201-
202- sentry_sdk .flush ()
203-
204- assert len (envelopes ) == 1
205-
206- assert len (envelopes [0 ].items [0 ].payload .json ["items" ]) == 2
207- assert envelopes [0 ].items [0 ].payload .json ["items" ][0 ]["name" ] == "span 1"
208- assert envelopes [0 ].items [0 ].payload .json ["items" ][1 ]["name" ] == "span 2"
209-
210- assert record_lost_event_calls .count (("queue_overflow" , "span" , None , 1 )) == 2
211-
212-
213- def test_capture_after_flush_with_global_limit (
214- sentry_init , capture_envelopes , monkeypatch
215- ):
216- """New spans are captured again after a flush reduces the span number below the global limit."""
217- monkeypatch .setattr (SpanBatcher , "GLOBAL_MAX_BEFORE_DROP" , 2 )
218- # set the time-based flush limit to something huge so that we're not flushing
219- # prematurely
220- monkeypatch .setattr (SpanBatcher , "FLUSH_WAIT_TIME" , 100000 )
221-
222- sentry_init (
223- traces_sample_rate = 1.0 ,
224- trace_lifecycle = "stream" ,
225- )
226-
227- envelopes = capture_envelopes ()
228-
229- with sentry_sdk .traces .start_span (name = "span 1" ):
230- pass
231- with sentry_sdk .traces .start_span (name = "span 2" ):
232- pass
233-
234- sentry_sdk .traces .new_trace ()
235- with sentry_sdk .traces .start_span (name = "span 3" ):
236- pass
237-
238- sentry_sdk .flush ()
239-
240- # The span is captured even though a span was dropped in the same trace.
241- with sentry_sdk .traces .start_span (name = "span 4" ):
242- pass
243-
244- sentry_sdk .flush ()
245-
246- assert len (envelopes ) == 2
247-
248- assert len (envelopes [0 ].items [0 ].payload .json ["items" ]) == 2
249- assert envelopes [0 ].items [0 ].payload .json ["items" ][0 ]["name" ] == "span 1"
250- assert envelopes [0 ].items [0 ].payload .json ["items" ][1 ]["name" ] == "span 2"
251-
252- assert len (envelopes [1 ].items [0 ].payload .json ["items" ]) == 1
253- assert envelopes [1 ].items [0 ].payload .json ["items" ][0 ]["name" ] == "span 4"
254-
255-
256174def test_length_based_flushing (sentry_init , capture_items , monkeypatch ):
257175 """A flush event is triggered when a bucket contains MAX_BEFORE_FLUSH spans."""
258176 monkeypatch .setattr (SpanBatcher , "MAX_BEFORE_FLUSH" , 1 )
@@ -338,130 +256,6 @@ def test_weight_based_flushing_by_attribute_size(
338256 assert envelopes [0 ].items [0 ].payload .json ["items" ][1 ]["name" ] == "big span"
339257
340258
341- def test_global_length_based_flushing (sentry_init , capture_items , monkeypatch ):
342- """A flush event is triggered when the batcher contains GLOBAL_MAX_BEFORE_FLUSH spans."""
343- monkeypatch .setattr (SpanBatcher , "GLOBAL_MAX_BEFORE_FLUSH" , 2 )
344- # set the time-based flush limit to something huge so that we're not hitting
345- # it since we want to test GLOBAL_MAX_BEFORE_FLUSH instead
346- monkeypatch .setattr (SpanBatcher , "FLUSH_WAIT_TIME" , 100000 )
347-
348- sentry_init (
349- traces_sample_rate = 1.0 ,
350- trace_lifecycle = "stream" ,
351- )
352-
353- items = capture_items ("span" )
354-
355- with sentry_sdk .traces .start_span (name = "span" ):
356- pass
357-
358- sentry_sdk .traces .new_trace ()
359- with sentry_sdk .traces .start_span (name = "span 2" ):
360- pass
361-
362- time .sleep (0.1 )
363-
364- assert len (items ) == 2
365- assert items [0 ].payload ["name" ] == "span"
366-
367-
368- def test_span_number_reset_after_length_based_flushing (
369- sentry_init , capture_items , monkeypatch
370- ):
371- """Span is not flushed after a flush reduces the number of spans in the batcher below the global limit."""
372- monkeypatch .setattr (SpanBatcher , "GLOBAL_MAX_BEFORE_FLUSH" , 2 )
373- # set the time-based flush limit to something huge so that we're not hitting
374- # it since we want to test GLOBAL_MAX_BYTES_BEFORE_FLUSH instead
375- monkeypatch .setattr (SpanBatcher , "FLUSH_WAIT_TIME" , 100000 )
376-
377- sentry_init (
378- traces_sample_rate = 1.0 ,
379- trace_lifecycle = "stream" ,
380- )
381-
382- items = capture_items ("span" )
383-
384- with sentry_sdk .traces .start_span (name = "span" ):
385- pass
386-
387- sentry_sdk .traces .new_trace ()
388- with sentry_sdk .traces .start_span (name = "span" ):
389- pass
390-
391- time .sleep (0.1 )
392-
393- with sentry_sdk .traces .start_span (name = "span" ):
394- pass
395-
396- time .sleep (0.1 )
397-
398- assert len (items ) == 2
399- assert items [0 ].payload ["name" ] == "span"
400-
401-
402- def test_global_weight_based_flushing (sentry_init , capture_items , monkeypatch ):
403- """When the batcher reaches GLOBAL_MAX_BYTES_BEFORE_FLUSH, all buckets will be flushed."""
404- # Limit of 2_000 is just above the size of a bare span.
405- monkeypatch .setattr (SpanBatcher , "GLOBAL_MAX_BYTES_BEFORE_FLUSH" , 2_000 )
406- # set the time-based flush limit to something huge so that it doesn't
407- # interfere
408- monkeypatch .setattr (SpanBatcher , "FLUSH_WAIT_TIME" , 100000 )
409-
410- sentry_init (
411- traces_sample_rate = 1.0 ,
412- trace_lifecycle = "stream" ,
413- )
414-
415- items = capture_items ("span" )
416-
417- with sentry_sdk .traces .start_span (name = "span" ):
418- pass
419-
420- sentry_sdk .traces .new_trace ()
421- with sentry_sdk .traces .start_span (name = "span" ):
422- pass
423-
424- time .sleep (0.1 )
425-
426- assert len (items ) == 2
427- assert items [0 ].payload ["name" ] == "span"
428-
429-
430- def test_total_size_reset_after_weight_based_flushing (
431- sentry_init , capture_items , monkeypatch
432- ):
433- """Span is not flushed after a flush reduces the combined span size in bytes below the global limit."""
434- # Limit of 2_000 is just above the size of a bare span.
435- monkeypatch .setattr (SpanBatcher , "GLOBAL_MAX_BYTES_BEFORE_FLUSH" , 2_000 )
436- # set the time-based flush limit to something huge so that it doesn't
437- # interfere
438- monkeypatch .setattr (SpanBatcher , "FLUSH_WAIT_TIME" , 100000 )
439-
440- sentry_init (
441- traces_sample_rate = 1.0 ,
442- trace_lifecycle = "stream" ,
443- )
444-
445- items = capture_items ("span" )
446-
447- with sentry_sdk .traces .start_span (name = "span" ):
448- pass
449-
450- sentry_sdk .traces .new_trace ()
451- with sentry_sdk .traces .start_span (name = "span" ):
452- pass
453-
454- time .sleep (0.1 )
455-
456- with sentry_sdk .traces .start_span (name = "span" ):
457- pass
458-
459- time .sleep (0.1 )
460-
461- assert len (items ) == 2
462- assert items [0 ].payload ["name" ] == "span"
463-
464-
465259def test_bucket_recreated_after_flush (sentry_init , capture_envelopes , monkeypatch ):
466260 """Spans for a trace that arrive after that trace's bucket was flushed land in a fresh bucket."""
467261 monkeypatch .setattr (SpanBatcher , "MAX_BEFORE_FLUSH" , 2 )
@@ -666,11 +460,7 @@ def test_span_batcher_lock_reset_in_child_after_fork(sentry_init):
666460 original_lock .acquire ()
667461
668462 batcher ._span_buffer ["test-trace-id" ].append (object ())
669- batcher ._span_number = 1
670-
671463 batcher ._running_size ["test-trace-id" ] = 42
672- batcher ._total_running_size = 42
673-
674464 batcher ._active .flag = True
675465 batcher ._flush_event .set ()
676466 batcher ._running = False
@@ -682,10 +472,7 @@ def test_span_batcher_lock_reset_in_child_after_fork(sentry_init):
682472
683473 flusher_reset = batcher ._flusher is None and batcher ._flusher_pid is None
684474 span_buffer_reset = len (batcher ._span_buffer ) == 0
685- span_number_reset = batcher ._span_number == 0
686-
687475 running_size_reset = len (batcher ._running_size ) == 0
688- total_running_size_reset = batcher ._total_running_size == 0
689476
690477 active_reset = not getattr (batcher ._active , "flag" , False )
691478 event_reset = not batcher ._flush_event .is_set ()
@@ -697,9 +484,7 @@ def test_span_batcher_lock_reset_in_child_after_fork(sentry_init):
697484 and unheld
698485 and flusher_reset
699486 and span_buffer_reset
700- and span_number_reset
701487 and running_size_reset
702- and total_running_size_reset
703488 and active_reset
704489 and event_reset
705490 and running_reset
0 commit comments