Skip to content

Commit 69866be

Browse files
Always sample checkin regardless of sample_rate (#2279)
* Always sample checkin regardless of sample_rate * Added test case for cron check-in * Test for sample rate affecting errors
1 parent d48d3eb commit 69866be

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

sentry_sdk/client.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -530,12 +530,16 @@ def capture_event(
530530
self._update_session_from_event(session, event)
531531

532532
is_transaction = event_opt.get("type") == "transaction"
533+
is_checkin = event_opt.get("type") == "check_in"
533534

534-
if not is_transaction and not self._should_sample_error(event):
535+
if (
536+
not is_transaction
537+
and not is_checkin
538+
and not self._should_sample_error(event)
539+
):
535540
return None
536541

537542
tracing_enabled = has_tracing_enabled(self.options)
538-
is_checkin = event_opt.get("type") == "check_in"
539543
attachments = hint.get("attachments")
540544

541545
trace_context = event_opt.get("contexts", {}).get("trace") or {}

tests/test_crons.py

+12
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,18 @@ def test_capture_checkin_simple(sentry_init):
8181
assert check_in_id == "112233"
8282

8383

84+
def test_sample_rate_doesnt_affect_crons(sentry_init, capture_envelopes):
85+
sentry_init(sample_rate=0)
86+
envelopes = capture_envelopes()
87+
88+
capture_checkin(check_in_id="112233")
89+
90+
assert len(envelopes) == 1
91+
92+
check_in = envelopes[0].items[0].payload.json
93+
assert check_in["check_in_id"] == "112233"
94+
95+
8496
def test_capture_checkin_new_id(sentry_init):
8597
sentry_init()
8698

tests/tracing/test_sampling.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import pytest
44

5-
from sentry_sdk import Hub, start_span, start_transaction
5+
from sentry_sdk import Hub, start_span, start_transaction, capture_exception
66
from sentry_sdk.tracing import Transaction
77
from sentry_sdk.utils import logger
88

@@ -226,6 +226,18 @@ def test_passes_custom_samling_context_from_start_transaction_to_traces_sampler(
226226
)
227227

228228

229+
def test_sample_rate_affects_errors(sentry_init, capture_events):
230+
sentry_init(sample_rate=0)
231+
events = capture_events()
232+
233+
try:
234+
1 / 0
235+
except Exception:
236+
capture_exception()
237+
238+
assert len(events) == 0
239+
240+
229241
@pytest.mark.parametrize(
230242
"traces_sampler_return_value",
231243
[

0 commit comments

Comments
 (0)