From c1f981222e22b3f29c5ecf5968b2367c18b42dec Mon Sep 17 00:00:00 2001 From: Gyuheon Oh Date: Fri, 17 Jul 2026 08:39:59 -0400 Subject: [PATCH 1/2] interval = 1 means to sample **every** exception --- ddtrace/profiling/collector/_exception.pyx | 7 ++++++- tests/profiling/collector/test_exception.py | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ddtrace/profiling/collector/_exception.pyx b/ddtrace/profiling/collector/_exception.pyx index eff31480c81..674c6526f19 100644 --- a/ddtrace/profiling/collector/_exception.pyx +++ b/ddtrace/profiling/collector/_exception.pyx @@ -131,7 +131,12 @@ cpdef void _on_exception(object code, int instruction_offset, object exception): if state.counter < state.next_sample: return - state.next_sample = max(state.sampler.sample(state.sampling_interval), 1) + # sampling_interval=1 means sample every exception. Skip Poisson so + # variance cannot insert gaps of 2+. + if state.sampling_interval == 1: + state.next_sample = 1 + else: + state.next_sample = max(state.sampler.sample(state.sampling_interval), 1) state.counter = 0 # At the raise site the head of the traceback is the raising frame; diff --git a/tests/profiling/collector/test_exception.py b/tests/profiling/collector/test_exception.py index ef66f2e75bb..8a0693f0732 100644 --- a/tests/profiling/collector/test_exception.py +++ b/tests/profiling/collector/test_exception.py @@ -808,7 +808,7 @@ def test_raise_fires_once_per_exception(tmp_path: Path) -> None: profile: pprof_pb2.Profile = pprof_utils.parse_newest_profile(output_filename) samples: list[pprof_pb2.Sample] = pprof_utils.get_samples_with_value_type(profile, "exception-samples") - # With sampling_interval=1, the first exception is always sampled. ddup aggregates samples + # With sampling_interval=1 every exception is sampled. ddup aggregates samples # with identical stacks into a single pprof row with a summed count value. # The invariant we are looking for is that the total exception-samples count for the # ValueError we raised must not exceed 1. From ff3d8d261f2cc797118b98d34c2860640176d942 Mon Sep 17 00:00:00 2001 From: Gyuheon Oh Date: Fri, 17 Jul 2026 08:43:08 -0400 Subject: [PATCH 2/2] Fix flaky test DD_VPBQBC DD_JTEUUX DD_6TMMN8 DD_841FBY DD_STXYRA DD_T3Z44N DD_TFZHZD DD_6VMAUN DD_SAXCT8