Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion ddtrace/profiling/collector/_exception.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/profiling/collector/test_exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading