Skip to content

Commit 8faf8fe

Browse files
bm1549claude
andauthored
fix(parametric): wait for client-side stats before asserting p0 dropping (#7326)
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 74cf797 commit 8faf8fe

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

tests/parametric/test_span_sampling.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,24 @@
2020
from .conftest import APMLibrary
2121

2222

23+
def _wait_for_client_side_stats_active(test_agent: TestAgentAPI, test_library: APMLibrary) -> None:
24+
"""Wait until client-side stats are active before asserting p0 dropping.
25+
26+
p0 dropping only turns on after the tracer's async `/info` handshake; spans flushed before it
27+
are forwarded undropped (a startup race). A received `/v0.6/stats` payload proves it is active.
28+
"""
29+
for _ in range(30):
30+
with test_library, test_library.dd_start_span(name="css-warmup", service="webserver"):
31+
pass
32+
try:
33+
test_agent.wait_for_num_v06_stats(1, wait_loops=10)
34+
except ValueError:
35+
continue
36+
test_agent.clear()
37+
return
38+
raise ValueError("client-side stats were not enabled in time; cannot reliably assert p0 dropping")
39+
40+
2341
@features.single_span_sampling
2442
@scenarios.parametric
2543
class Test_Span_Sampling:
@@ -625,6 +643,7 @@ def test_root_span_selected_and_child_dropped_by_sss_when_dropping_policy_is_act
625643
the activate dropping policy.
626644
"""
627645
assert test_agent.info()["client_drop_p0s"] is True, "Client drop p0s expected to be enabled"
646+
_wait_for_client_side_stats_active(test_agent, test_library)
628647

629648
with test_library, test_library.dd_start_span(name="parent", service="webserver"):
630649
pass
@@ -684,6 +703,7 @@ def test_child_span_selected_and_root_dropped_by_sss_when_dropping_policy_is_act
684703
the activate dropping policy.
685704
"""
686705
assert test_agent.info()["client_drop_p0s"] is True, "Client drop p0s expected to be enabled"
706+
_wait_for_client_side_stats_active(test_agent, test_library)
687707

688708
with (
689709
test_library,
@@ -737,6 +757,7 @@ def test_entire_trace_dropped_when_dropping_policy_is_active018(
737757
the activate dropping policy.
738758
"""
739759
assert test_agent.info()["client_drop_p0s"] is True, "Client drop p0s expected to be enabled"
760+
_wait_for_client_side_stats_active(test_agent, test_library)
740761

741762
with test_library, test_library.dd_start_span(name="parent", service="webserver"):
742763
pass

0 commit comments

Comments
 (0)