Skip to content

Commit 46e60d7

Browse files
committed
tests: Add client report tests for span streaming
1 parent 6ea663f commit 46e60d7

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

tests/tracing/test_span_streaming.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,59 @@ def test_continue_trace_unsampled(sentry_init, capture_envelopes):
641641
assert len(spans) == 0
642642

643643

644+
def test_unsampled_spans_produce_client_report(
645+
sentry_init, capture_envelopes, capture_record_lost_event_calls
646+
):
647+
sentry_init(
648+
traces_sample_rate=0.0,
649+
_experiments={"trace_lifecycle": "stream"},
650+
)
651+
652+
envelopes = capture_envelopes()
653+
record_lost_event_calls = capture_record_lost_event_calls()
654+
655+
with sentry_sdk.traces.start_span(name="segment"):
656+
with sentry_sdk.traces.start_span(name="child1"):
657+
pass
658+
with sentry_sdk.traces.start_span(name="child2"):
659+
pass
660+
661+
sentry_sdk.get_client().flush()
662+
663+
spans = envelopes_to_spans(envelopes)
664+
assert not spans
665+
666+
assert record_lost_event_calls == [
667+
("sample_rate", "span", None, 1),
668+
("sample_rate", "span", None, 1),
669+
("sample_rate", "span", None, 1),
670+
]
671+
672+
673+
def test_no_client_reports_if_tracing_is_off(
674+
sentry_init, capture_envelopes, capture_record_lost_event_calls
675+
):
676+
sentry_init(
677+
traces_sample_rate=None,
678+
_experiments={"trace_lifecycle": "stream"},
679+
)
680+
681+
envelopes = capture_envelopes()
682+
record_lost_event_calls = capture_record_lost_event_calls()
683+
684+
with sentry_sdk.traces.start_span(name="segment"):
685+
with sentry_sdk.traces.start_span(name="child1"):
686+
pass
687+
with sentry_sdk.traces.start_span(name="child2"):
688+
pass
689+
690+
sentry_sdk.get_client().flush()
691+
692+
spans = envelopes_to_spans(envelopes)
693+
assert not spans
694+
assert not record_lost_event_calls
695+
696+
644697
def test_continue_trace_no_sample_rand(sentry_init, capture_envelopes):
645698
sentry_init(
646699
# parent sampling decision takes precedence over traces_sample_rate
@@ -1324,6 +1377,36 @@ def test_ignore_spans_reparenting(sentry_init, capture_envelopes):
13241377
assert span5["parent_span_id"] == span3["span_id"]
13251378

13261379

1380+
def test_ignored_spans_produce_client_report(
1381+
sentry_init, capture_envelopes, capture_record_lost_event_calls
1382+
):
1383+
sentry_init(
1384+
traces_sample_rate=1.0,
1385+
_experiments={"trace_lifecycle": "stream", "ignore_spans": ["ignored"]},
1386+
)
1387+
1388+
envelopes = capture_envelopes()
1389+
record_lost_event_calls = capture_record_lost_event_calls()
1390+
1391+
with sentry_sdk.traces.start_span(name="ignored"):
1392+
with sentry_sdk.traces.start_span(name="span1"):
1393+
pass
1394+
with sentry_sdk.traces.start_span(name="span2"):
1395+
pass
1396+
1397+
sentry_sdk.get_client().flush()
1398+
1399+
spans = envelopes_to_spans(envelopes)
1400+
assert not spans
1401+
1402+
# All three spans will be ignored since the segment is ignored
1403+
assert record_lost_event_calls == [
1404+
("ignored", "span", None, 1),
1405+
("ignored", "span", None, 1),
1406+
("ignored", "span", None, 1),
1407+
]
1408+
1409+
13271410
@mock.patch("sentry_sdk.profiler.continuous_profiler.DEFAULT_SAMPLING_FREQUENCY", 21)
13281411
def test_segment_span_has_profiler_id(
13291412
sentry_init, capture_envelopes, teardown_profiling

0 commit comments

Comments
 (0)